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]";
Checking Software Version Script
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Checking Software Version Script
I'm not sure where you are doing this but I would think this
should be this
Additionally I don't see where you are setting $status
Code: Select all
if ($current_info !== $sw){Code: Select all
if ($current_info != $sw){Re: Checking Software Version Script
$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
$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
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...