Page 1 of 1

Checking Software Version Script

Posted: Mon Aug 27, 2012 11:16 am
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]";

Re: Checking Software Version Script

Posted: Mon Aug 27, 2012 11:53 am
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

Re: Checking Software Version Script

Posted: Mon Aug 27, 2012 1:50 pm
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

Re: Checking Software Version Script

Posted: Mon Aug 27, 2012 5:04 pm
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...