Checking Software Version Script

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
LuisN
Posts: 40
Joined: Thu May 24, 2012 10:47 am

Checking Software Version Script

Post by LuisN »

Hi Guys,, can you help me here. How come this wont work?

im passing the $sw via the command externally,
but everytime its always CRITICAL. i am trying to make it so IF my defined SW version is != to the Current one on the server then Warn, If its missing, then Critical, if it matches then its OK

exec("snmpget -v 2c -c public $host $oid | cut -d':' -f4 | sed -e 's/^[ ]*//'", $info);
$current_info = ($info[0]);
if ($current_info !== $sw){
$aux = "CRITICAL - $current_info | RPM=$current_info";
if ($status < 2)
$status = 2;
}
else if ($current_info > $sw){
$aux = "WARNING - $current_info | RPM=$current_info";
if ($status < 1)
$status = 1;
}
else{
$aux = "OK - $current_info | RPM=$current_info";
}

$msg .= "$aux $current_info[0]";
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Checking Software Version Script

Post by scottwilkerson »

I'm not sure where you are doing this but I would think this

Code: Select all

if ($current_info !== $sw){
should be this

Code: Select all

if ($current_info != $sw){
Additionally I don't see where you are setting $status
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
LuisN
Posts: 40
Joined: Thu May 24, 2012 10:47 am

Re: Checking Software Version Script

Post by LuisN »

$msg = "";
$status = 0;
for ($i=0; $i<sizeof($oid); $i++){
$passing_oid=$oid[$i];
//$passing_name=$oid_name[$i];
$info = "";
exec("snmpget -v 2c -c public $host $oid | cut -d':' -f4 | sed -e 's/^[ ]*//'", $info);
$current_info = ($info[0]);
print_r($sw);

if ($current_info != $sw){
$aux = "CRITICAL - $current_info | RPM=$current_info";
if ($status < 2)
$status = 2;
}
else if ($current_info > $sw){
$aux = "WARNING - $current_info | RPM=$current_info";
if ($status < 1)
$status = 1;
}
else{
$aux = "OK - $current_info | RPM=$current_info";
}

$msg .= "$aux $current_info[0]";
}
$msg = substr($msg, 0 , -1);

if ($msg == "")
$status = 3;


doing the != for some reason doesnt take. not sure why
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Checking Software Version Script

Post by scottwilkerson »

I'm confused with your script, it appears you are setting $status = 0; to 0 then testing if it is something other than 0 throughout the script befor doing anything...
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked