convert more to internal snmp,

polling/os/unix: switch to snmp_get(), reindent, add ARM processors, patch by Corentin Chary

git-svn-id: http://www.observium.org/svn/observer/trunk@1813 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2011-03-10 15:31:57 +00:00
parent c6664c10c4
commit a199070100
3 changed files with 61 additions and 47 deletions

View File

@@ -1,49 +1,62 @@
<?php
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" || $device['os'] == "solaris" || $device['os'] == "opensolaris") {
list(,,$version,$features,$hardware) = explode (" ", $sysDescr);
$features = str_replace("(", "", $features);
$features = str_replace(")", "", $features);
} elseif ($device['os'] == "monowall" || $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"; }
else if(strstr($sysDescr, "x86_64")) { $hardware = "Generic x86 64-bit"; }
else if(strstr($sysDescr, "sparc32")) { $hardware = "Generic SPARC 32-bit"; }
else if(strstr($sysDescr, "sparc64")) { $hardware = "Generic SPARC 64-bit"; }
# Distro "extend" support
$cmd = $config['snmpget'] . " -M ".$config['mibdir'] . " -m UCD-SNMP-MIB -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|grep -v 'No Such Instance'";
$features = trim(`$cmd`);
$features = str_replace("\"", "", $features);
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" || $device['os'] == "solaris" || $device['os'] == "opensolaris")
{
list(,,$version,$features,$hardware) = explode (" ", $sysDescr);
$features = str_replace("(", "", $features);
$features = str_replace(")", "", $features);
}
elseif ($device['os'] == "monowall" || $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"; }
else if(strstr($sysDescr, "x86_64")) { $hardware = "Generic x86 64-bit"; }
else if(strstr($sysDescr, "sparc32")) { $hardware = "Generic SPARC 32-bit"; }
else if(strstr($sysDescr, "sparc64")) { $hardware = "Generic SPARC 64-bit"; }
else if(strstr($sysDescr, "armv5")) { $hardware = "Generic ARMv5"; }
else if(strstr($sysDescr, "armv6")) { $hardware = "Generic ARMv6"; }
else if(strstr($sysDescr, "armv7")) { $hardware = "Generic ARMv7"; }
else if(strstr($sysDescr, "armv")) { $hardware = "Generic ARM"; }
# Distro "extend" support
$features = snmp_get($device, ".1.3.6.1.4.1.2021.7890.1.3.1.1.6.100.105.115.116.114.111", "-Oqv", "UCD-SNMP-MIB");
$features = str_replace("\"", "", $features);
if (!$features) // No "extend" support, try "exec" support
{
$features = snmp_get($device, ".1.3.6.1.4.1.2021.7890.1.101.1", "-Oqv", "UCD-SNMP-MIB");
$features = str_replace("\"", "", $features);
}
if (!$features) # No "extend" support, try "exec" support
{
$cmd = $config['snmpget'] . " -M ".$config['mibdir'] . " -m UCD-SNMP-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']. " .1.3.6.1.4.1.2021.7890.1.101.1|grep -v 'No Such Instance'";
$features = trim(`$cmd`);
$features = str_replace("\"", "", $features);
}
if(preg_match("@No\ Such@", $features)||preg_match("@No\ such@", $features)) { unset($features); }
// Detect Dell hardware via OpenManage SNMP
$cmd = $config['snmpget'] . " -M ".$config['mibdir'] . " -m MIB-Dell-10892 -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";
$hw = trim(str_replace("\"", "", `$cmd`));
if(strpos($hw, "No") !== FALSE) { unset($hw); } else { $hardware = "Dell " . $hw; }
}
// Detect Dell hardware via OpenManage SNMP
$hw = snmp_get($device, ".1.3.6.1.4.1.674.10892.1.300.10.1.9.1", "-Oqv", "MIB-Dell-10892");
$hw = trim(str_replace("\"", "", $hw));
if ($hw) { $hardware = "Dell " . $hw; }
}
?>

View File

@@ -128,6 +128,7 @@
$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));
## Check to see that the OIDs are actually populated before we make the rrd
@@ -163,8 +164,7 @@
RRA:MAX:0.5:288:800";
$load_get = "laLoadInt.1 laLoadInt.2 laLoadInt.3";
$load_cmd = $config['snmpget']. " -M ".$config['mibdir']." -m UCD-SNMP-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $load_get;
$load_raw = `$load_cmd`;
$load_raw = snmp_get($device, $load_get, "-Oqv", "UCD-SNMP-MIB");
list ($load1, $load5, $load10) = explode ("\n", $load_raw);
## Check to see that the OIDs are actually populated before we make the rrd
@@ -176,3 +176,4 @@
rrdtool_update($load_rrd, "N:$load1:$load5:$load10");
$graphs['ucd_load'] = "TRUE";
}
?>

View File

@@ -122,7 +122,7 @@ while ($device = mysql_fetch_assoc($device_query))
$snmp_cmd .= " sysUpTime.0 sysLocation.0 sysContact.0 sysName.0";
$snmpdata = str_replace('"','',trim(shell_exec($snmp_cmd)));
list($sysUptime, $sysLocation, $sysContact, $sysName) = explode("\n", $snmpdata);
$sysDescr = trim(shell_exec($config['snmpget'] . " -m SNMPv2-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " sysDescr.0"));
$sysDescr = trim(snmp_get($device, "sysDescr.0", "-Oqv", "SNMPv2-MIB"));
$sysName = strtolower($sysName);
$hrSystemUptime = snmp_get($device, "HOST-RESOURCES-MIB::hrSystemUptime.0", "-Oqv");