--------------------
the script make use of:
https://secure.asteas.com/docu/interfacing/batch_access.html
-------------------


#!/usr/bin/perl
use strict;
use Data::Dumper;
use JSON;
###############################################################################
#
# checkIACBox
#
# see also: https://secure.asteas.com/docu/interfacing/batch_access.html
#
# use IACBOX api, to get some data out of the IACBOX, return results back in check syntax
#
# usage:
#
# ./checkIACBOX.pl <hostname or ip-address> <iac-user> <iac-pwd> <warning-online>
#
###############################################################################
my $version='v2022-30-03';
my $user='';
my $pwd='';
my $url='';
my $warning_online = 90; #warning if more users are online, than this percentage number
my $debug=0;
my %retHash = {};

if ($ARGV[0] eq '' ){
print "Usage: checkIACBox.pl <hostname or ip-address> <iac-user> <iac-pwd> <warning-online>\n";
print "\n";
exit(1);
}
my $ip=$ARGV[0];
$user=$ARGV[1];
$pwd=$ARGV[2];
$warning_online==$ARGV[3];

my $url='https://'.$ip.'/batch.php';

print "<<<check_mk>>>\n";
print "Version: pn-$version\n";
print "<<<local>>>\n";

getUserInfo();

##################
# Sub-Routines
##################

#get User Info
#curl --insecure --data "username=xyz&password=xyz&action=json&want=userinfo" https://192.168.2.33/batch.php
#{"users_online":1,"lic_users":"25","max_users":"25","percent_onl":4,"percent_free":96,"reg_number":"2018070502"}
sub getUserInfo(){
my $cmd = 'curl --insecure --data "username='.$user.'&password='.$pwd.'&action=json&want=userinfo" '.$url;
my $users_online=0;
my $max_users=-1;
my $percent_online=0;
my $i=0;
my $servicename = "IACBOX-Users";
my $line='';

print "cmd=$cmd\n" if $debug;
open(IN, "$cmd 2>/dev/null |");
while(<IN>){
$i++;
$line = $_;
chomp($line);
print "$i: $line\n" if $debug;
#line is something like:
# 1: {"users_online":4,"lic_users":"25","max_users":"25","percent_onl":16,"percent_free":84,"reg_number":"2022033001"}
#

my $ret = decode_json($line);
%retHash = %$ret;
print Dumper(%retHash) if $debug;
if ($retHash{'users_online'}){
$users_online=$retHash{'users_online'};
}
if ($retHash{'max_users'}){
$max_users=$retHash{'max_users'};
}
if ($retHash{'percent_onl'}){
$percent_online=$retHash{'percent_onl'};
}
#print Dumper($users_online) if $debug;
}
#$max_users=0;
if ($max_users <= 0){
print "1 $servicename users=$users_online warning - max_users value should be > 0! Maybe problem with getting values from IACBOX! (Last result from query was >> $line << ).\n";
return;
}
if ($percent_online > $warning_online ){
print "1 $servicename users=$users_online warning - more than $warning_online% of users are online! $users_online / max: $max_users are online. Percent online = $perce nt_online.\n";
return;
}
print "0 $servicename users=$users_online ok - $users_online / max: $max_users are online. Percent online = $percent_online. Warning if > than $warning_online%.\n";
}

computer2know :: thank you for your visit :: have a nice day :: © 2024