2007-04-08 14:33:42 +00:00
< ? php
2009-03-16 15:19:44 +00:00
$loadrrd = $config [ 'rrd_dir' ] . " / " . $device [ 'hostname' ] . " /load.rrd " ;
$cpurrd = $config [ 'rrd_dir' ] . " / " . $device [ 'hostname' ] . " /cpu.rrd " ;
$memrrd = $config [ 'rrd_dir' ] . " / " . $device [ 'hostname' ] . " /mem.rrd " ;
$sysrrd = $config [ 'rrd_dir' ] . " / " . $device [ 'hostname' ] . " /sys.rrd " ;
2008-03-12 13:55:50 +00:00
2008-11-26 17:58:47 +00:00
if ( $device [ 'os' ] == " FreeBSD " ) {
$sysDescr = str_replace ( " 0 " , " " , $sysDescr );
list (,, $version ) = explode ( " " , $sysDescr );
$hardware = " i386 " ;
$features = " GENERIC " ;
} elseif ( $device [ 'os' ] == " DragonFly " ) {
list (,, $version ,,, $features ,, $hardware ) = explode ( " " , $sysDescr );
} elseif ( $device [ 'os' ] == " NetBSD " ) {
list (,, $version ,,, $features ) = explode ( " " , $sysDescr );
$features = str_replace ( " ( " , " " , $features );
$features = str_replace ( " ) " , " " , $features );
list (,, $hardware ) = explode ( " $features " , $sysDescr );
} elseif ( $device [ 'os' ] == " OpenBSD " ) {
list (,, $version , $features , $hardware ) = explode ( " " , $sysDescr );
$features = str_replace ( " ( " , " " , $features );
$features = str_replace ( " ) " , " " , $features );
} elseif ( $device [ 'os' ] == " m0n0wall " || $device [ 'os' ] == " Voswall " ) {
list (,, $version , $hardware , $freebsda , $freebsdb , $arch ) = split ( " " , $sysDescr );
$features = $freebsda . " " . $freebsdb ;
$hardware = " $hardware ( $arch ) " ;
$hardware = str_replace ( " \" " , " " , $hardware );
} elseif ( $device [ 'os' ] == " Linux " ) {
list (,, $version ) = explode ( " " , $sysDescr );
if ( strstr ( $sysDescr , " 386 " ) || strstr ( $sysDescr , " 486 " ) || strstr ( $sysDescr , " 586 " ) || strstr ( $sysDescr , " 686 " )) { $hardware = " Generic x86 " ; }
if ( strstr ( $sysDescr , " x86_64 " )) { $hardware = " Generic x86 64-bit " ; }
2009-03-02 18:12:09 +00:00
$cmd = " snmpget -O qv - " . $device [ 'snmpver' ] . " -c " . $device [ 'community' ] . " " . $device [ 'hostname' ] . " : " . $device [ 'port' ] . " .1.3.6.1.4.1.2021.7890.1.3.1.1.6.100.105.115.116.114.111 " ;
2008-11-26 17:58:47 +00:00
$features = trim ( `$cmd` );
$features = str_replace ( " No Such Object available on this agent at this OID " , " " , $features );
$features = str_replace ( " \" " , " " , $features );
// Detect Dell hardware via OpenManage SNMP
2009-02-02 16:00:11 +00:00
$cmd = " snmpget -O qv - " . $device [ 'snmpver' ] . " -c " . $device [ 'community' ] . " " . $device [ 'hostname' ] . " : " . $device [ 'port' ] . " .1.3.6.1.4.1.674.10892.1.300.10.1.9.1 " ;
2008-11-26 17:58:47 +00:00
$hw = trim ( str_replace ( " \" " , " " , `$cmd` ));
if ( strstr ( $hw , " No " )) { unset ( $hw ); } else { $hardware = " Dell " . $hw ; }
}
2007-04-08 14:33:42 +00:00
## Check Disks
2007-11-23 11:37:28 +00:00
$dq = mysql_query ( " SELECT * FROM storage WHERE host_id = ' " . $device [ 'device_id' ] . " ' " );
2007-04-08 14:33:42 +00:00
while ( $dr = mysql_fetch_array ( $dq )) {
$hrStorageIndex = $dr [ 'hrStorageIndex' ];
$hrStorageAllocationUnits = $dr [ 'hrStorageAllocationUnits' ];
$hrStorageSize = $dr [ 'hrStorageAllocationUnits' ] * $dr [ 'hrStorageSize' ];
$hrStorageDescr = $dr [ 'hrStorageDescr' ];
2009-04-23 21:13:56 +00:00
$cmd = " snmpget -m HOST-RESOURCES-MIB -O qv - " . $device [ 'snmpver' ] . " -c " . $device [ 'community' ] . " " . $device [ 'hostname' ] . " : " . $device [ 'port' ] . " hrStorageUsed. $hrStorageIndex " ;
2007-05-20 19:21:35 +00:00
$used_units = trim ( `$cmd` );
$used = $used_units * $hrStorageAllocationUnits ;
$perc = round ( $used / $hrStorageSize * 100 , 2 );
2007-04-08 14:33:42 +00:00
$filedesc = str_replace ( " \" " , " " , str_replace ( " / " , " _ " , $hrStorageDescr ));
2008-03-12 13:55:50 +00:00
2009-03-16 15:19:44 +00:00
$storage_rrd = $config [ 'rrd_dir' ] . " / " . $device [ 'hostname' ] . " /storage- " . $filedesc . " .rrd " ;
2008-03-12 13:55:50 +00:00
if ( ! is_file ( $storage_rrd )) {
2008-04-10 14:52:51 +00:00
shell_exec ( $config [ 'rrdtool' ] . " create $storage_rrd \
2007-04-08 14:33:42 +00:00
-- step 300 \
DS : size : GAUGE : 600 : 0 : U \
DS : used : GAUGE : 600 : 0 : U \
DS : perc : GAUGE : 600 : 0 : U \
RRA : AVERAGE : 0.5 : 1 : 800 \
RRA : AVERAGE : 0.5 : 6 : 800 \
RRA : AVERAGE : 0.5 : 24 : 800 \
RRA : AVERAGE : 0.5 : 288 : 800 \
RRA : MAX : 0.5 : 1 : 800 \
RRA : MAX : 0.5 : 6 : 800 \
RRA : MAX : 0.5 : 24 : 800 \
2008-04-10 14:52:51 +00:00
RRA : MAX : 0.5 : 288 : 800 " );
2007-04-08 14:33:42 +00:00
}
2008-03-12 13:55:50 +00:00
rrdtool_update ( $storage_rrd , " N: $hrStorageSize : $used : $perc " );
2007-05-20 19:21:35 +00:00
mysql_query ( " UPDATE `storage` SET `hrStorageUsed` = ' $used_units ', `storage_perc` = ' $perc ' WHERE storage_id = ' " . $dr [ 'storage_id' ] . " ' " );
2007-11-23 11:37:28 +00:00
if ( $dr [ 'storage_perc' ] < '40' && $perc >= '40' ) {
if ( $device [ 'sysContact' ]) { $email = $device [ 'sysContact' ]; } else { $email = $config [ 'email_default' ]; }
$msg = " Disk Alarm: " . $device [ 'hostname' ] . " " . $dr [ 'hrStorageDescr' ] . " is " . $perc ;
$msg .= " at " . date ( 'l dS F Y h:i:s A' );
mail ( $email , " Disk Alarm: " . $device [ 'hostname' ] . " " . $dr [ 'hrStorageDescr' ], $msg , $config [ 'email_headers' ]);
echo ( " Alerting for " . $device [ 'hostname' ] . " " . $dr [ 'hrStorageDescr' ] . " /n " );
}
2007-04-08 14:33:42 +00:00
}
## Set OIDs
$oid_ssCpuRawUser = " .1.3.6.1.4.1.2021.11.50.0 " ;
$oid_ssCpuRawNice = " .1.3.6.1.4.1.2021.11.51.0 " ;
$oid_ssCpuRawSystem = " .1.3.6.1.4.1.2021.11.52.0 " ;
$oid_ssCpuRawIdle = " .1.3.6.1.4.1.2021.11.53.0 " ;
2008-03-09 17:39:14 +00:00
2007-04-08 14:33:42 +00:00
$oid_hrSystemProcesses = " .1.3.6.1.2.1.25.1.6.0 " ;
$oid_hrSystemNumUsers = " .1.3.6.1.2.1.25.1.5.0 " ;
2008-03-09 17:39:14 +00:00
$oid_ssCpuUser = " .1.3.6.1.4.1.2021.11.9.0 " ;
$oid_ssCpuSystem = " .1.3.6.1.4.1.2021.11.10.0 " ;
2009-04-23 21:13:56 +00:00
$cpu_cmd = $config [ 'snmpget' ] . " -m UCD-SNMP-MIB:HOST-RESOURCES-MIB -O qv - " . $device [ 'snmpver' ] . " -c " . $device [ 'community' ] . " " . $device [ 'hostname' ] . " : " . $device [ 'port' ];
2007-04-08 18:09:21 +00:00
$cpu_cmd .= " $oid_ssCpuRawUser $oid_ssCpuRawSystem $oid_ssCpuRawNice $oid_ssCpuRawIdle $oid_hrSystemProcesses " ;
2009-04-23 21:13:56 +00:00
$cpu_cmd .= " $oid_hrSystemNumUsers $oid_ssCpuUser $oid_ssCpuSystem " ;
2007-04-08 18:09:21 +00:00
$cpu = `$cpu_cmd` ;
2009-04-23 21:13:56 +00:00
list ( $cpuUser , $cpuSystem , $cpuNice , $cpuIdle , $procs , $users , $UsageUser , $UsageSystem ) = explode ( " \n " , $cpu );
2008-03-09 17:39:14 +00:00
2008-03-23 21:32:54 +00:00
$cpuUsage = $UsageUser + $UsageSystem ;
2008-03-09 17:39:14 +00:00
2008-03-23 21:32:54 +00:00
if ( mysql_result ( mysql_query ( " SELECT COUNT(*) FROM devices_attribs WHERE `device_id` = ' " . $device [ 'device_id' ] . " ' AND `attrib_type` = 'cpuusage' " ), 0 )) {
$update_usage = mysql_query ( " UPDATE devices_attribs SET attrib_value = ' $cpuUsage ' WHERE `device_id` = ' " . $device [ 'device_id' ] . " ' AND `attrib_type` = 'cpuusage' " );
} else {
2008-03-09 17:39:14 +00:00
$insert_usage = mysql_query ( " INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES (' " . $device [ 'device_id' ] . " ', 'cpuusage', ' $cpuUsage ') " );
}
2007-04-08 14:33:42 +00:00
## Create CPU RRD if it doesn't already exist
if ( ! is_file ( $cpurrd )) {
2008-04-10 14:52:51 +00:00
shell_exec ( $config [ 'rrdtool' ] . " create $cpurrd \
2007-04-08 14:33:42 +00:00
-- step 300 \
DS : user : COUNTER : 600 : 0 : U \
DS : system : COUNTER : 600 : 0 : U \
DS : nice : COUNTER : 600 : 0 : U \
DS : idle : COUNTER : 600 : 0 : U \
RRA : AVERAGE : 0.5 : 1 : 800 \
RRA : AVERAGE : 0.5 : 6 : 800 \
RRA : AVERAGE : 0.5 : 24 : 800 \
RRA : AVERAGE : 0.5 : 288 : 800 \
RRA : MAX : 0.5 : 1 : 800 \
RRA : MAX : 0.5 : 6 : 800 \
RRA : MAX : 0.5 : 24 : 800 \
2008-04-10 14:52:51 +00:00
RRA : MAX : 0.5 : 288 : 800 " );
2007-04-08 14:33:42 +00:00
}
2008-03-09 21:13:27 +00:00
rrdtool_update ( $cpurrd , " N: $cpuUser : $cpuSystem : $cpuNice : $cpuIdle " );
2007-04-08 14:33:42 +00:00
## If the device isn't monowall or pfsense, monitor all the pretty things
if ( $device [ os ] != " m0n0wall " && $device [ os ] != " Voswall " && $device [ os ] != " pfSense " ) {
if ( ! is_file ( $sysrrd )) {
2008-04-10 14:52:51 +00:00
shell_exec ( $config [ 'rrdtool' ] . " create $sysrrd \
2007-04-08 14:33:42 +00:00
-- step 300 \
DS : users : GAUGE : 600 : 0 : U \
DS : procs : GAUGE : 600 : 0 : U \
RRA : AVERAGE : 0.5 : 1 : 800 \
RRA : AVERAGE : 0.5 : 6 : 800 \
RRA : AVERAGE : 0.5 : 24 : 800 \
RRA : AVERAGE : 0.5 : 288 : 800 \
RRA : MAX : 0.5 : 1 : 800 \
RRA : MAX : 0.5 : 6 : 800 \
RRA : MAX : 0.5 : 24 : 800 \
2008-04-10 14:52:51 +00:00
RRA : MAX : 0.5 : 288 : 800 " );
2007-04-08 14:33:42 +00:00
}
if ( ! is_file ( $memrrd )) {
2008-04-10 14:52:51 +00:00
shell_exec ( $config [ 'rrdtool' ] . " create $memrrd \
2007-04-08 14:33:42 +00:00
-- step 300 \
DS : totalswap : GAUGE : 600 : 0 : 10000000000 \
DS : availswap : GAUGE : 600 : 0 : 10000000000 \
DS : totalreal : GAUGE : 600 : 0 : 10000000000 \
DS : availreal : GAUGE : 600 : 0 : 10000000000 \
DS : totalfree : GAUGE : 600 : 0 : 10000000000 \
DS : shared : GAUGE : 600 : 0 : 10000000000 \
DS : buffered : GAUGE : 600 : 0 : 10000000000 \
DS : cached : GAUGE : 600 : 0 : 10000000000 \
RRA : AVERAGE : 0.5 : 1 : 800 \
RRA : AVERAGE : 0.5 : 6 : 800 \
RRA : AVERAGE : 0.5 : 24 : 800 \
RRA : AVERAGE : 0.5 : 288 : 800 \
RRA : MAX : 0.5 : 1 : 800 \
RRA : MAX : 0.5 : 6 : 800 \
RRA : MAX : 0.5 : 24 : 800 \
2008-04-10 14:52:51 +00:00
RRA : MAX : 0.5 : 288 : 800 " );
2007-04-08 14:33:42 +00:00
} // end create mem rrd
if ( ! is_file ( $loadrrd )) {
2008-04-10 14:52:51 +00:00
shell_exec ( $config [ 'rrdtool' ] . " create $loadrrd \
2007-04-08 14:33:42 +00:00
-- step 300 \
DS : 1 min : GAUGE : 600 : 0 : 5000 \
DS : 5 min : GAUGE : 600 : 0 : 5000 \
DS : 15 min : GAUGE : 600 : 0 : 5000 \
RRA : AVERAGE : 0.5 : 1 : 800 \
RRA : AVERAGE : 0.5 : 6 : 800 \
RRA : AVERAGE : 0.5 : 24 : 800 \
RRA : AVERAGE : 0.5 : 288 : 800 \
RRA : MAX : 0.5 : 1 : 800 \
RRA : MAX : 0.5 : 6 : 800 \
RRA : MAX : 0.5 : 24 : 800 \
2008-04-10 14:52:51 +00:00
RRA : MAX : 0.5 : 288 : 800 " );
2007-04-08 14:33:42 +00:00
} // end create load rrd
2009-04-23 21:13:56 +00:00
$mem_cmd = $config [ 'snmpget' ] . " -m UCD-SNMP-MIB -O qv - " . $device [ 'snmpver' ] . " -c " . $device [ 'community' ] . " " . $device [ 'hostname' ] . " : " . $device [ 'port' ];
$mem_cmd .= " memTotalSwap.0 memAvailSwap.0 memTotalReal.0 memAvailReal.0 memTotalFree.0 memShared.0 memBuffer.0 memCached.0 " ;
$mem_raw = shell_exec ( $mem_cmd );
list ( $memTotalSwap , $memAvailSwap , $memTotalReal , $memAvailReal , $memTotalFree , $memShared , $memBuffer , $memCached ) = explode ( " \n " , str_replace ( " kB " , " " , $mem_raw ));
2007-04-08 14:33:42 +00:00
$load_get = " laLoadInt.1 laLoadInt.2 laLoadInt.3 " ;
2009-04-23 21:13:56 +00:00
$load_cmd = " snmpget -m UCD-SNMP-MIB -O qv - " . $device [ 'snmpver' ] . " -c " . $device [ 'community' ] . " " . $device [ 'hostname' ] . " : " . $device [ 'port' ] . " " . $load_get ;
2007-04-08 14:33:42 +00:00
$load_raw = `$load_cmd` ;
list ( $load1 , $load5 , $load10 ) = explode ( " \n " , $load_raw );
2008-03-09 21:13:27 +00:00
rrdtool_update ( $sysrrd , " N: $users : $procs " );
rrdtool_update ( $loadrrd , " N: $load1 : $load5 : $load10 " );
rrdtool_update ( $memrrd , " N: $memTotalSwap : $memAvailSwap : $memTotalReal : $memAvailReal : $memTotalFree : $memShared : $memBuffer : $memCached " );
2007-04-08 14:33:42 +00:00
} // end Non-m0n0wall