2009-09-07 11:07:59 +00:00
< ? php
2007-05-20 19:21:35 +00:00
$id = $device [ 'device_id' ];
2007-04-03 18:15:19 +00:00
$hostname = $device [ 'hostname' ];
$community = $device [ 'community' ];
$snmpver = $device [ 'snmpver' ];
2009-02-02 16:00:11 +00:00
$port = $device [ 'port' ];
2008-03-22 23:09:35 +00:00
echo ( " Temperatures : " );
2007-11-23 11:37:28 +00:00
2008-08-11 09:40:05 +00:00
## JunOS Temperatures
if ( $device [ 'os' ] == " JunOS " ) {
echo ( " JunOS " );
2009-04-24 15:04:45 +00:00
$oids = shell_exec ( $config [ 'snmpwalk' ] . " -m JUNIPER-MIB - $snmpver -CI -Osqn -c $community $hostname : $port 1.3.6.1.4.1.2636.3.1.13.1.7 " );
2008-08-11 09:40:05 +00:00
$oids = trim ( $oids );
foreach ( explode ( " \n " , $oids ) as $data ) {
$data = trim ( $data );
$data = substr ( $data , 29 );
if ( $data ) {
list ( $oid ) = explode ( " " , $data );
$temp_oid = " 1.3.6.1.4.1.2636.3.1.13.1.7. $oid " ;
$descr_oid = " 1.3.6.1.4.1.2636.3.1.13.1.5. $oid " ;
2009-04-24 15:04:45 +00:00
$descr = trim ( shell_exec ( $config [ 'snmpget' ] . " -m JUNIPER-MIB -O qv - $snmpver -c $community $hostname : $port $descr_oid " ));
$temp = trim ( shell_exec ( $config [ 'snmpget' ] . " -m JUNIPER-MIB -O qv - $snmpver -c $community $hostname : $port $temp_oid " ));
2008-08-11 09:40:05 +00:00
if ( ! strstr ( $descr , " No " ) && ! strstr ( $temp , " No " ) && $descr != " " && $temp != " 0 " ) {
2009-04-24 15:04:45 +00:00
$descr = shell_exec ( $config [ 'snmpget' ] . " -m JUNIPER-MIB -O qv - $snmpver -c $community $hostname : $port $descr_oid " );
2008-08-11 09:40:05 +00:00
$descr = str_replace ( " \" " , " " , $descr );
$descr = str_replace ( " temperature " , " " , $descr );
$descr = str_replace ( " temp " , " " , $descr );
$descr = trim ( $descr );
if ( mysql_result ( mysql_query ( " SELECT count(temp_id) FROM `temperature` WHERE temp_oid = ' $temp_oid ' AND temp_host = ' $id ' " ), 0 ) == '0' ) {
$query = " INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`) values (' $id ', ' $temp_oid ', ' $descr ') " ;
mysql_query ( $query );
echo ( " + " );
} else { echo ( " . " ); }
$temp_exists [] = " $id $temp_oid " ;
}
}
}
}
2007-11-23 11:37:28 +00:00
## Begin Observer-Style
if ( $device [ 'os' ] == " Linux " ) {
2008-03-22 23:09:35 +00:00
echo ( " Observer-Style " );
2009-04-24 15:04:45 +00:00
$oids = shell_exec ( $config [ 'snmpwalk' ] . " - $snmpver -m SNMPv2-SMI -Osqn -CI -c $community $hostname : $port .1.3.6.1.4.1.2021.7891 | sed s/.1.3.6.1.4.1.2021.7891.// | grep '.1.1 ' | grep -v '.101.' | cut -d'.' -f 1 " );
2007-11-23 11:37:28 +00:00
$oids = trim ( $oids );
foreach ( explode ( " \n " , $oids ) as $oid ) {
$oid = trim ( $oid );
if ( $oid != " " ) {
2009-04-24 15:04:45 +00:00
$descr_query = $config [ 'snmpget' ] . " - $snmpver -m SNMPv2-SMI -Osqn -c $community $hostname : $port .1.3.6.1.4.1.2021.7891. $oid .2.1 | sed s/.1.3.6.1.4.1.2021.7891. $oid .2.1 \ // " ;
$descr = trim ( str_replace ( " \" " , " " , shell_exec ( $descr_query )));
2007-11-23 11:37:28 +00:00
$fulloid = " .1.3.6.1.4.1.2021.7891. $oid .101.1 " ;
if ( ! mysql_result ( mysql_query ( " SELECT count(temp_id) FROM temperature WHERE `temp_host` = ' $id ' AND `temp_oid` = ' $fulloid ' " ), 0 )) {
2008-03-22 23:09:35 +00:00
echo ( " + " );
2007-11-23 11:37:28 +00:00
mysql_query ( " INSERT INTO `temperature` (`temp_host`,`temp_oid`,`temp_descr`) VALUES (' $id ', ' $fulloid ', ' $descr '); " );
2008-03-22 23:09:35 +00:00
} elseif ( mysql_result ( mysql_query ( " SELECT `temp_descr` FROM temperature WHERE `temp_host` = ' $id ' AND `temp_oid` = ' $fulloid ' " ), 0 ) != $descr ) {
echo ( " U " );
mysql_query ( " UPDATE temperature SET `temp_descr` = ' $descr ' WHERE `temp_host` = ' $id ' AND `temp_oid` = ' $fulloid ' " );
} else {
echo ( " . " );
2007-11-23 11:37:28 +00:00
}
$temp_exists [] = " $id $fulloid " ;
}
2007-06-06 16:43:08 +00:00
}
2007-11-23 11:37:28 +00:00
} ## End Observer-Style
## Dell Temperatures
if ( strstr ( $device [ 'hardware' ], " Dell " )) {
2008-03-22 23:09:35 +00:00
echo ( " Dell OMSA " );
2009-04-24 15:04:45 +00:00
$oids = shell_exec ( $config [ 'snmpwalk' ] . " -m MIB-Dell-10892 - $snmpver -CI -Osqn -c $community $hostname : $port .1.3.6.1.4.1.674.10892.1.700.20.1.8 " );
2007-11-23 11:37:28 +00:00
$oids = trim ( $oids );
foreach ( explode ( " \n " , $oids ) as $oid ) {
$oid = substr ( trim ( $oid ), 36 );
list ( $oid ) = explode ( " " , $oid );
if ( $oid != " " ) {
2009-04-24 15:04:45 +00:00
$descr_query = $config [ 'snmpget' ] . " -m MIB-Dell-10892 - $snmpver -Onvq -c $community $hostname : $port .1.3.6.1.4.1.674.10892.1.700.20.1.8. $oid " ;
$descr = trim ( str_replace ( " \" " , " " , shell_exec ( $descr_query )));
2007-11-23 11:37:28 +00:00
$fulloid = " .1.3.6.1.4.1.674.10892.1.700.20.1.6. $oid " ;
if ( ! mysql_result ( mysql_query ( " SELECT count(temp_id) FROM temperature WHERE `temp_host` = ' $id ' AND `temp_oid` = ' $fulloid ' " ), 0 )) {
mysql_query ( " INSERT INTO `temperature` (`temp_host`,`temp_oid`,`temp_descr`, `temp_tenths`) VALUES (' $id ', ' $fulloid ', ' $descr ', '1'); " );
2008-03-22 23:09:35 +00:00
echo ( " + " );
} elseif ( mysql_result ( mysql_query ( " SELECT `temp_descr` FROM temperature WHERE `temp_host` = ' $id ' AND `temp_oid` = ' $fulloid ' " ), 0 ) != $descr ) {
mysql_query ( " UPDATE temperature SET `temp_descr` = ' $descr ' WHERE `temp_host` = ' $id ' AND `temp_oid` = ' $fulloid ' " );
2009-04-24 15:04:45 +00:00
echo ( " UPDATE temperature SET `temp_descr` = ' $descr ' WHERE `temp_host` = ' $id ' AND `temp_oid` = ' $fulloid ' " );
2008-03-22 23:09:35 +00:00
echo ( " U " );
2007-11-23 11:37:28 +00:00
} else {
2008-03-22 23:09:35 +00:00
echo ( " . " );
2007-11-23 11:37:28 +00:00
}
$temp_exists [] = " $id $fulloid " ;
}
}
} ## End Dell Sensors
## Cisco Temperatures
2009-04-11 19:10:48 +00:00
if ( $device [ 'os' ] == " IOS " || $device [ 'os' ] == " IOS XE " ) {
2008-03-22 23:09:35 +00:00
echo ( " Cisco " );
2009-04-24 15:04:45 +00:00
$oids = shell_exec ( $config [ 'snmpwalk' ] . " -m CISCO-ENVMON-MIB - $snmpver -CI -Osqn -c $community $hostname : $port .1.3.6.1.4.1.9.9.13.1.3.1.2 | sed s/.1.3.6.1.4.1.9.9.13.1.3.1.2.//g " );
2007-11-23 11:37:28 +00:00
$oids = trim ( $oids );
foreach ( explode ( " \n " , $oids ) as $data ) {
2008-03-22 23:09:35 +00:00
$data = trim ( $data );
if ( $data ) {
2007-11-23 11:37:28 +00:00
list ( $oid ) = explode ( " " , $data );
$temp_oid = " .1.3.6.1.4.1.9.9.13.1.3.1.3. $oid " ;
$descr_oid = " .1.3.6.1.4.1.9.9.13.1.3.1.2. $oid " ;
2009-04-24 15:04:45 +00:00
$descr = shell_exec ( $config [ 'snmpget' ] . " -m CISCO-ENVMON-MIB -O qv - $snmpver -c $community $hostname : $port $descr_oid " );
$temp = shell_exec ( $config [ 'snmpget' ] . " -m CISCO-ENVMON-MIB -O qv - $snmpver -c $community $hostname : $port $temp_oid " );
2007-11-23 11:37:28 +00:00
if ( ! strstr ( $descr , " No " ) && ! strstr ( $temp , " No " ) && $descr != " " ) {
2009-04-24 15:04:45 +00:00
$descr = shell_exec ( $config [ 'snmpget' ] . " -m CISCO-ENVMON-MIB -O qv - $snmpver -c $community $hostname : $port $descr_oid " );
2007-11-23 11:37:28 +00:00
$descr = str_replace ( " \" " , " " , $descr );
$descr = str_replace ( " temperature " , " " , $descr );
$descr = str_replace ( " temp " , " " , $descr );
$descr = trim ( $descr );
if ( mysql_result ( mysql_query ( " SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '.1.3.6.1.4.1.9.9.13.1.3.1.3. $oid ' AND temp_host = ' $id ' " ), 0 ) == '0' ) {
$query = " INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`) values (' $id ', ' $temp_oid ', ' $descr ') " ;
mysql_query ( $query );
2008-03-22 23:09:35 +00:00
echo ( " + " );
} else { echo ( " . " ); }
2007-11-23 11:37:28 +00:00
$temp_exists [] = " $id $temp_oid " ;
}
2008-03-22 23:09:35 +00:00
}
2007-11-23 11:37:28 +00:00
}
2008-08-11 09:40:05 +00:00
} ## End Cisco Temperatures
2008-03-22 23:09:35 +00:00
2007-06-06 16:43:08 +00:00
2007-11-23 11:37:28 +00:00
## Delete removed sensors
2007-06-06 16:43:08 +00:00
2008-03-22 23:09:35 +00:00
$sql = " SELECT * FROM temperature AS T, devices AS D WHERE T.temp_host = D.device_id AND D.device_id = ' " . $device [ 'device_id' ] . " ' " ;
2007-05-20 19:21:35 +00:00
$query = mysql_query ( $sql );
while ( $sensor = mysql_fetch_array ( $query )) {
unset ( $exists );
$i = 0 ;
while ( $i < count ( $temp_exists ) && ! $exists ) {
$thistemp = $sensor [ 'temp_host' ] . " " . $sensor [ 'temp_oid' ];
2007-06-06 09:23:41 +00:00
if ( $temp_exists [ $i ] == $thistemp ) { $exists = 1 ; }
2007-05-20 19:21:35 +00:00
$i ++ ;
}
if ( ! $exists ) {
2008-03-22 23:09:35 +00:00
echo ( " - " );
2007-06-06 09:23:41 +00:00
mysql_query ( " DELETE FROM temperature WHERE temp_id = ' " . $sensor [ 'temp_id' ] . " ' " );
2007-05-20 19:21:35 +00:00
}
}
2008-03-22 23:09:35 +00:00
unset ( $temp_exists ); echo ( " \n " );
2007-05-20 19:21:35 +00:00
2007-04-03 18:15:19 +00:00
2008-03-22 23:09:35 +00:00
?>