/** * Build a commandline string for net-snmp commands. * * @param string $command * @param array $device * @param string $oids * @param string $options * @param string $mib * @param string $mibdir * @global config * @global debug * @return string */ function snmp_command($command, $device, $oids, $options, $mib = NULL, $mibdir = NULL) { global $debug, $config; // Get the full command path from the config. Chose between bulkwalk and walk. Add max-reps if needed. switch ($command) { case "snmpwalk": if ($device['snmpver'] == 'v1' || isset($config['os'][$device['os']]['nobulk']) && $config['os'][$device['os']]['nobulk']) { $cmd = $config['snmpwalk']; } else { $cmd = $config['snmpbulkwalk']; if ($config['snmp']['max-rep'] && is_numeric($config['os'][$device['os']]['snmp']['max-rep'])) { $cmd .= ' -Cr' . $config['os'][$device['os']]['snmp']['max-rep']; } } break; case "snmpget": $cmd = $config[$command]; break; case "snmpbulkget": if ($device['snmpver'] == 'v1' || isset($config['os'][$device['os']]['nobulk']) && $config['os'][$device['os']]['nobulk']) { $cmd = $config['snmpget']; } else { $cmd = $config['snmpbulkget']; if ($config['snmp']['max-rep'] && is_numeric($config['os'][$device['os']]['snmp']['max-rep'])) { $cmd .= ' -Cr' . $config['os'][$device['os']]['snmp']['max-rep']; } } break; default: echo "THIS SHOULD NOT HAPPEN. PLEASE REPORT."; return FALSE; } // Set timeout values if set in the database if (is_numeric($device['timeout']) && $device['timeout'] > 0) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } if (isset($timeout)) { $cmd .= " -t " . escapeshellarg($timeout); } // Set retries if set in the database if (is_numeric($device['retries']) && $device['retries'] >= 0) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; } if (isset($retries)) { $cmd .= " -r " . escapeshellarg($retries); } // If no transport is set in the database, default to UDP. if (!isset($device['transport'])) { $device['transport'] = "udp"; } // Add the SNMP authentication settings for the device $cmd .= snmp_gen_auth($device); if ($options) { $cmd .= " " . $options; } if ($mib) { $cmd .= " -m " . $mib; } if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M " . $config['mib_dir']; } // Add the device URI to the string $cmd .= " " . escapeshellarg($device['transport']) . ":" . escapeshellarg($device['hostname']) . ":" . escapeshellarg($device['port']); // Add the OID(s) to the strong $cmd .= " " . $oids; // If we're not debugging, direct errors to /dev/null. if (!$debug) { $cmd .= " 2>/dev/null"; } return $cmd; }
function snmp_cache_portName($device, $array) { global $config; if (is_numeric($device['timeout']) && $device['timeout'] > 0) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; } if (is_numeric($device['retries']) && $device['retries'] > 0) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; } if (!isset($device['transport'])) { $device['transport'] = "udp"; } $cmd = $config['snmpwalk']; $cmd .= snmp_gen_auth($device); $cmd .= " -CI -m CISCO-STACK-MIB -O Qs"; $cmd .= mibdir(null); if (isset($timeout)) { $cmd .= " -t " . $timeout; } if (isset($retries)) { $cmd .= " -r " . $retries; } $cmd .= " " . $device['transport'] . ":" . $device['hostname'] . ":" . $device['port'] . " portName"; $output = trim(external_exec($cmd)); $device_id = $device['device_id']; #echo("Caching: portName\n"); foreach (explode("\n", $output) as $entry) { $entry = str_replace("portName.", "", $entry); list($slotport, $portName) = explode("=", $entry, 2); $slotport = trim($slotport); $portName = trim($portName); if ($array[$slotport]['ifIndex']) { $ifIndex = $array[$slotport]['ifIndex']; $array[$slotport]['portName'] = $portName; $array[$ifIndex]['portName'] = $portName; } } return $array; }
$peer['update']['bgpPeerInUpdates'] = $bgpPeerInUpdates; $peer['update']['bgpLocalAddr'] = $bgpLocalAddr; $peer['update']['bgpPeerOutUpdates'] = $bgpPeerOutUpdates; dbUpdate($peer['update'], 'bgpPeers', '`device_id` = ? AND `bgpPeerIdentifier` = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])); if ($device['os_group'] == "cisco" || $device['os'] == "junos") { // Poll each AFI/SAFI for this peer (using CISCO-BGP4-MIB or BGP4-V2-JUNIPER MIB) $peer_afis = dbFetchRows("SELECT * FROM bgpPeers_cbgp WHERE `device_id` = ? AND bgpPeerIdentifier = ?", array($device['device_id'], $peer['bgpPeerIdentifier'])); foreach ($peer_afis as $peer_afi) { $afi = $peer_afi['afi']; $safi = $peer_afi['safi']; if ($debug) { echo "{$afi} {$safi}\n"; } if ($device['os_group'] == "cisco") { // FIXME - move to function $cbgp_cmd = $config['snmpget'] . " -M " . $config['mibdir'] . " -m CISCO-BGP4-MIB -Ovq " . snmp_gen_auth($device) . " " . $device['hostname'] . ":" . $device['port']; $cbgp_cmd .= " cbgpPeerAcceptedPrefixes." . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= " cbgpPeerDeniedPrefixes." . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= " cbgpPeerPrefixAdminLimit." . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= " cbgpPeerPrefixThreshold." . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= " cbgpPeerPrefixClearThreshold." . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= " cbgpPeerAdvertisedPrefixes." . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= " cbgpPeerSuppressedPrefixes." . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= " cbgpPeerWithdrawnPrefixes." . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; if ($debug) { echo "{$cbgp_cmd}\n"; } $cbgp_data = preg_replace("/^OID.*\$/", "", trim(`{$cbgp_cmd}`)); $cbgp_data = preg_replace("/No Such Instance currently exists at this OID/", "0", $cbgp_data); if ($debug) { echo "{$cbgp_data}\n";
unset($temp_data); $temp_data['cbgpPeer2AcceptedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2AcceptedPrefixes']; $temp_data['cbgpPeer2DeniedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2DeniedPrefixes']; $temp_data['cbgpPeer2PrefixAdminLimit'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixAdminLimit']; $temp_data['cbgpPeer2PrefixThreshold'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixThreshold']; $temp_data['cbgpPeer2PrefixClearThreshold'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixClearThreshold']; $temp_data['cbgpPeer2AdvertisedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2AdvertisedPrefixes']; $temp_data['cbgpPeer2SuppressedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2SuppressedPrefixes']; $temp_data['cbgpPeer2WithdrawnPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2WithdrawnPrefixes']; foreach ($temp_data as $k => $v) { $cbgp_data .= "{$v}\n"; } d_echo("{$cbgp_data}\n"); } else { // FIXME - move to function $cbgp_cmd = $config['snmpget'] . ' -M ' . $config['mibdir'] . ' -m CISCO-BGP4-MIB -Ovq ' . snmp_gen_auth($device) . ' ' . $device['hostname'] . ':' . $device['port']; $cbgp_cmd .= ' cbgpPeerAcceptedPrefixes.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= ' cbgpPeerDeniedPrefixes.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= ' cbgpPeerPrefixAdminLimit.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= ' cbgpPeerPrefixThreshold.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= ' cbgpPeerPrefixClearThreshold.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= ' cbgpPeerAdvertisedPrefixes.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= ' cbgpPeerSuppressedPrefixes.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; $cbgp_cmd .= ' cbgpPeerWithdrawnPrefixes.' . $peer['bgpPeerIdentifier'] . ".{$afi}.{$safi}"; d_echo("{$cbgp_cmd}\n"); $cbgp_data = preg_replace('/^OID.*$/', '', trim(`{$cbgp_cmd}`)); $cbgp_data = preg_replace('/No Such Instance currently exists at this OID/', '0', $cbgp_data); d_echo("{$cbgp_data}\n"); } //end if list($cbgpPeerAcceptedPrefixes, $cbgpPeerDeniedPrefixes, $cbgpPeerPrefixAdminLimit, $cbgpPeerPrefixThreshold, $cbgpPeerPrefixClearThreshold, $cbgpPeerAdvertisedPrefixes, $cbgpPeerSuppressedPrefixes, $cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data);
<?php // FIXME - this is lame if (!empty($agent_data['app']['mysql'])) { $mysql = $agent_data['app']['mysql']; } else { #Polls MySQL statistics from script via SNMP $mysql_cmd = $config['snmpget'] . " -m NET-SNMP-EXTEND-MIB -O qv " . snmp_gen_auth($device) . " " . $device['hostname'] . ":" . $device['port']; $mysql_cmd .= " nsExtendOutputFull.5.109.121.115.113.108"; $mysql = shell_exec($mysql_cmd); } $mysql_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-mysql-" . $app['app_id'] . ".rrd"; echo " mysql"; $data = explode("\n", $mysql); $map = array(); foreach ($data as $str) { list($key, $value) = explode(":", $str); $map[$key] = (double) trim($value); #$nstring .= (float)trim($elements[1]).":"; } // General Stats $mapping = array('IDBLBSe' => 'cr', 'IBLFh' => 'ct', 'IBLWn' => 'cu', 'IBLWn' => 'cu', 'SRows' => 'ck', 'SRange' => 'cj', 'SMPs' => 'ci', 'SScan' => 'cl', 'IBIRd' => 'ai', 'IBIWr' => 'aj', 'IBILg' => 'ak', 'IBIFSc' => 'ah', 'IDBRDd' => 'b2', 'IDBRId' => 'b0', 'IDBRRd' => 'b3', 'IDBRUd' => 'b1', 'IBRd' => 'ae', 'IBCd' => 'af', 'IBWr' => 'ag', 'TLIe' => 'b5', 'TLWd' => 'b4', 'IBPse' => 'aa', 'IBPDBp' => 'ac', 'IBPFe' => 'ab', 'IBPMps' => 'ad', 'TOC' => 'bc', 'OFs' => 'b7', 'OTs' => 'b8', 'OdTs' => 'b9', 'IBSRs' => 'ay', 'IBSWs' => 'ax', 'IBOWs' => 'az', 'QCs' => 'c1', 'QCeFy' => 'bu', 'MaCs' => 'bl', 'MUCs' => 'bf', 'ACs' => 'bd', 'AdCs' => 'be', 'TCd' => 'bi', 'Cs' => 'bn', 'IBTNx' => 'a5', 'KRRs' => 'a0', 'KRs' => 'a1', 'KWR' => 'a2', 'KWs' => 'a3', 'QCQICe' => 'bz', 'QCHs' => 'bv', 'QCIs' => 'bw', 'QCNCd' => 'by', 'QCLMPs' => 'bx', 'CTMPDTs' => 'cn', 'CTMPTs' => 'cm', 'CTMPFs' => 'co', 'IBIIs' => 'au', 'IBIMRd' => 'av', 'IBIMs' => 'aw', 'IBILog' => 'al', 'IBISc' => 'am', 'IBIFLg' => 'an', 'IBFBl' => 'aq', 'IBIIAo' => 'ap', 'IBIAd' => 'as', 'IBIAe' => 'at', 'SFJn' => 'cd', 'SFRJn' => 'ce', 'SRe' => 'cf', 'SRCk' => 'cg', 'SSn' => 'ch', 'SQs' => 'b6', 'BRd' => 'cq', 'BSt' => 'cp', 'CDe' => 'c6', 'CIt' => 'c4', 'CISt' => 'ca', 'CLd' => 'c8', 'CRe' => 'c7', 'CRSt' => 'cc', 'CSt' => 'c5', 'CUe' => 'c3', 'CUMi' => 'c9'); $values = array(); foreach ($mapping as $key) { $values[] = isset($map[$key]) ? $map[$key] : -1; } $string = implode(':', $values); if (!is_file($mysql_rrd)) { rrdtool_create($mysql_rrd, "--step 300 \\\n DS:IDBLBSe:GAUGE:600:0:125000000000 \\\n DS:IBLFh:DERIVE:600:0:125000000000 \\\n DS:IBLWn:DERIVE:600:0:125000000000 \\\n DS:SRows:DERIVE:600:0:125000000000 \\\n DS:SRange:DERIVE:600:0:125000000000 \\\n DS:SMPs:DERIVE:600:0:125000000000 \\\n DS:SScan:DERIVE:600:0:125000000000 \\\n DS:IBIRd:DERIVE:600:0:125000000000 \\\n DS:IBIWr:DERIVE:600:0:125000000000 \\\n DS:IBILg:DERIVE:600:0:125000000000 \\\n DS:IBIFSc:DERIVE:600:0:125000000000 \\\n DS:IDBRDd:DERIVE:600:0:125000000000 \\\n DS:IDBRId:DERIVE:600:0:125000000000 \\\n DS:IDBRRd:DERIVE:600:0:125000000000 \\\n DS:IDBRUd:DERIVE:600:0:125000000000 \\\n DS:IBRd:DERIVE:600:0:125000000000 \\\n DS:IBCd:DERIVE:600:0:125000000000 \\\n DS:IBWr:DERIVE:600:0:125000000000 \\\n DS:TLIe:DERIVE:600:0:125000000000 \\\n DS:TLWd:DERIVE:600:0:125000000000 \\\n DS:IBPse:GAUGE:600:0:125000000000 \\\n DS:IBPDBp:GAUGE:600:0:125000000000 \\\n DS:IBPFe:GAUGE:600:0:125000000000 \\\n DS:IBPMps:GAUGE:600:0:125000000000 \\\n DS:TOC:GAUGE:600:0:125000000000 \\\n DS:OFs:GAUGE:600:0:125000000000 \\\n DS:OTs:GAUGE:600:0:125000000000 \\\n DS:OdTs:COUNTER:600:0:125000000000 \\\n DS:IBSRs:DERIVE:600:0:125000000000 \\\n DS:IBSWs:DERIVE:600:0:125000000000 \\\n DS:IBOWs:DERIVE:600:0:125000000000 \\\n DS:QCs:GAUGE:600:0:125000000000 \\\n DS:QCeFy:GAUGE:600:0:125000000000 \\\n DS:MaCs:GAUGE:600:0:125000000000 \\\n DS:MUCs:GAUGE:600:0:125000000000 \\\n DS:ACs:DERIVE:600:0:125000000000 \\\n DS:AdCs:DERIVE:600:0:125000000000 \\\n DS:TCd:GAUGE:600:0:125000000000 \\\n DS:Cs:DERIVE:600:0:125000000000 \\\n DS:IBTNx:DERIVE:600:0:125000000000 \\\n DS:KRRs:DERIVE:600:0:125000000000 \\\n DS:KRs:DERIVE:600:0:125000000000 \\\n DS:KWR:DERIVE:600:0:125000000000 \\\n DS:KWs:DERIVE:600:0:125000000000 \\\n DS:QCQICe:DERIVE:600:0:125000000000 \\\n DS:QCHs:DERIVE:600:0:125000000000 \\\n DS:QCIs:DERIVE:600:0:125000000000 \\\n DS:QCNCd:DERIVE:600:0:125000000000 \\\n DS:QCLMPs:DERIVE:600:0:125000000000 \\\n DS:CTMPDTs:DERIVE:600:0:125000000000 \\\n DS:CTMPTs:DERIVE:600:0:125000000000 \\\n DS:CTMPFs:DERIVE:600:0:125000000000 \\\n DS:IBIIs:DERIVE:600:0:125000000000 \\\n DS:IBIMRd:DERIVE:600:0:125000000000 \\\n DS:IBIMs:DERIVE:600:0:125000000000 \\\n DS:IBILog:DERIVE:602:0:125000000000 \\\n DS:IBISc:DERIVE:602:0:125000000000 \\\n DS:IBIFLg:DERIVE:600:0:125000000000 \\\n DS:IBFBl:DERIVE:600:0:125000000000 \\\n DS:IBIIAo:DERIVE:600:0:125000000000 \\\n DS:IBIAd:DERIVE:600:0:125000000000 \\\n DS:IBIAe:DERIVE:600:0:125000000000 \\\n DS:SFJn:DERIVE:600:0:125000000000 \\\n DS:SFRJn:DERIVE:600:0:125000000000 \\\n DS:SRe:DERIVE:600:0:125000000000 \\\n DS:SRCk:DERIVE:600:0:125000000000 \\\n DS:SSn:DERIVE:600:0:125000000000 \\\n DS:SQs:DERIVE:600:0:125000000000 \\\n DS:BRd:DERIVE:600:0:125000000000 \\\n DS:BSt:DERIVE:600:0:125000000000 \\\n DS:CDe:DERIVE:600:0:125000000000 \\\n DS:CIt:DERIVE:600:0:125000000000 \\\n DS:CISt:DERIVE:600:0:125000000000 \\\n DS:CLd:DERIVE:600:0:125000000000 \\\n DS:CRe:DERIVE:600:0:125000000000 \\\n DS:CRSt:DERIVE:600:0:125000000000 \\\n DS:CSt:DERIVE:600:0:125000000000 \\\n DS:CUe:DERIVE:600:0:125000000000 \\\n DS:CUMi:DERIVE:600:0:125000000000 " . $config['rrd_rra']); } rrdtool_update($mysql_rrd, "N:{$string}");
function snmp_command($command, $device, $oids, $options, $mib = NULL, $mibdir = NULL, $flags = OBS_SNMP_ALL) { global $config; // This is compatibility code after refactor in r6306, for keep devices up before DB updated if (isset($device['snmpver']) && !isset($device['snmp_version'])) { // FIXME. Remove this in r7000 $device['snmp_version'] = $device['snmpver']; foreach (array('transport', 'port', 'timeout', 'retries', 'community', 'authlevel', 'authname', 'authpass', 'authalgo', 'cryptopass', 'cryptoalgo') as $old_key) { // Convert to new device snmp keys $device['snmp_' . $old_key] = $device[$old_key]; } } $nobulk = $device['snmp_version'] == 'v1' || isset($device['snmp_nobulk']) && $device['snmp_nobulk'] || isset($config['os'][$device['os']]['snmp']['nobulk']) && $config['os'][$device['os']]['snmp']['nobulk']; // Get the full command path from the config. Chose between bulkwalk and walk. Add max-reps if needed. switch ($command) { case 'snmpwalk': if ($nobulk) { $cmd = $config['snmpwalk']; } else { $cmd = $config['snmpbulkwalk']; if ($config['snmp']['max-rep'] && is_numeric($config['os'][$device['os']]['snmp']['max-rep'])) { $cmd .= ' -Cr' . $config['os'][$device['os']]['snmp']['max-rep']; } } if (isset($config['os'][$device['os']]['snmp']['noincrease']) && $config['os'][$device['os']]['snmp']['noincrease']) { // do not check returned OIDs are increasing $cmd .= ' -Cc'; } break; case 'snmpget': $cmd = $config[$command]; break; case 'snmpbulkget': if ($nobulk) { $cmd = $config['snmpget']; } else { $cmd = $config['snmpbulkget']; if ($config['snmp']['max-rep'] && is_numeric($config['os'][$device['os']]['snmp']['max-rep'])) { $cmd .= ' -Cr' . $config['os'][$device['os']]['snmp']['max-rep']; } } break; default: print_error("Unknown command {$command} passed to snmp_command(). THIS SHOULD NOT HAPPEN. PLEASE REPORT TO DEVELOPERS."); return FALSE; } // Set timeout values if set in the database, otherwise set to configured defaults if (is_numeric($device['snmp_timeout']) && $device['snmp_timeout'] > 0) { $snmp_timeout = $device['snmp_timeout']; } else { if (isset($config['snmp']['timeout'])) { $snmp_timeout = $config['snmp']['timeout']; } } if (isset($snmp_timeout)) { $cmd .= ' -t ' . escapeshellarg($snmp_timeout); } // Set retries if set in the database, otherwise set to configured defaults if (is_numeric($device['snmp_retries']) && $device['snmp_retries'] >= 0) { $snmp_retries = $device['snmp_retries']; } else { if (isset($config['snmp']['retries'])) { $snmp_retries = $config['snmp']['retries']; } } if (isset($snmp_retries)) { $cmd .= ' -r ' . escapeshellarg($snmp_retries); } // If no specific transport is set for the device, default to UDP. if (empty($device['snmp_transport'])) { $device['snmp_transport'] = 'udp'; } // If no specific port is set for the device, default to 161. if (!$device['snmp_port']) { $device['snmp_port'] = 161; } // Add the SNMP authentication settings for the device $cmd .= snmp_gen_auth($device); // Hardcode ignoring underscore parsing errors because net-snmp is dumb as a bag of rocks $cmd .= ' -Pu'; // Disables the use of DISPLAY-HINT information when assigning values. if (is_flag_set(OBS_SNMP_HEX, $flags)) { $cmd .= ' -Ih'; } if ($options) { $cmd .= ' ' . $options; } if ($mib) { $cmd .= ' -m ' . $mib; } // Set correct MIB directories based on passed dirs and OS definition // If $mibdir variable is passed, we use it directly if ($mibdir) { $cmd .= " -M {$mibdir}"; } else { $cmd .= ' -M ' . snmp_mib2mibdirs($mib); } // Add the device URI to the string $cmd .= ' ' . escapeshellarg($device['snmp_transport']) . ':' . escapeshellarg($device['hostname']) . ':' . escapeshellarg($device['snmp_port']); // Add the OID(s) to the string $cmd .= ' ' . $oids; // If we're not debugging, direct errors to /dev/null. if (!OBS_DEBUG) { $cmd .= ' 2>/dev/null'; } return $cmd; }
<?php echo "Polling SNOM device...\n"; // Get SNOM specific version string from silly SNOM location. Silly SNOM! // FIXME - This needs a good cleanup... $cmd = "snmpget -O qv " . snmp_gen_auth($device) . " " . $device['hostname'] . ":" . $device['port'] . " 1.3.6.1.2.1.7526.2.4"; $poll_device['sysDescr'] = `{$cmd}`; $poll_device['sysDescr'] = str_replace("-", " ", $poll_device['sysDescr']); $poll_device['sysDescr'] = str_replace("\"", "", $poll_device['sysDescr']); list($hardware, $features, $version) = explode(" ", $poll_device['sysDescr']); // Get data for calls and network from SNOM specific SNMP OIDs. $cmda = "snmpget -O qv " . snmp_gen_auth($device) . " " . $device['hostname'] . ":" . $device['port'] . " 1.3.6.1.2.1.7526.2.1.1 1.3.6.1.2.1.7526.2.1.2 1.3.6.1.2.1.7526.2.2.1 1.3.6.1.2.1.7526.2.2.2"; $cmdb = "snmpget -O qv " . snmp_gen_auth($device) . " " . $device['hostname'] . ":" . $device['port'] . " 1.3.6.1.2.1.7526.2.5 1.3.6.1.2.1.7526.2.6"; #echo($cmda); $snmpdata = `{$cmda}`; $snmpdatab = `{$cmdb}`; list($rxbytes, $rxpkts, $txbytes, $txpkts) = explode("\n", $snmpdata); list($calls, $registrations) = explode("\n", $snmpdatab); $txbytes = 0 - $txbytes * 8; $rxbytes = 0 - $rxbytes * 8; echo "{$rxbytes}, {$rxpkts}, {$txbytes}, {$txpkts}, {$calls}, {$registrations}"; $rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/data.rrd"; if (!is_file($rrdfile)) { rrdtool_create($rrdfile, "DS:INOCTETS:COUNTER:600:U:100000000000 \\\n DS:OUTOCTETS:COUNTER:600:U:10000000000 \\\n DS:INPKTS:COUNTER:600:U:10000000000 \\\n DS:OUTPKTS:COUNTER:600:U:10000000000 \\\n DS:CALLS:COUNTER:600:U:10000000000 \\\n DS:REGISTRATIONS:COUNTER:600:U:10000000000 " . $config['rrd_rra']); } $rrdupdate = "N:{$rxbytes}:{$txbytes}:{$rxpkts}:{$rxbytes}:{$calls}:{$registrations}"; rrdtool_update("{$rrdfile}", $rrdupdate);
<?php #FIXME snmp_ function! $hardware = trim(exec($config['snmpget'] . " -M " . $config['mibdir'] . " -O vqs -m FOUNDRY-SN-AGENT-MIB:FOUNDRY-SN-ROOT-MIB " . snmp_gen_auth($device) . " " . $device['hostname'] . ":" . $device['port'] . " sysObjectID.0")); $hardware = rewrite_ironware_hardware($hardware); $version = trim(exec($config['snmpget'] . " -M " . $config['mibdir'] . " -O vqs -m FOUNDRY-SN-AGENT-MIB:FOUNDRY-SN-ROOT-MIB " . snmp_gen_auth($device) . " " . $device['hostname'] . ":" . $device['port'] . " snAgBuildVer.0")); $version = str_replace("V", "", $version); $version = str_replace("\"", "", $version);
<?php $version = preg_replace("/(.+)\\ version\\ (.+)\\ \\(SN:\\ (.+)\\,\\ (.+)\\)/", "\\1||\\2||\\3||\\4", $poll_device['sysDescr']); list($hardware, $version, $serial, $features) = explode("||", $version); $sessrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/screenos_sessions.rrd"; $sess_cmd = $config['snmpget'] . " -M " . $config['mibdir'] . " -O qv " . snmp_gen_auth($device) . " " . $device['hostname']; $sess_cmd .= " .1.3.6.1.4.1.3224.16.3.2.0 .1.3.6.1.4.1.3224.16.3.3.0 .1.3.6.1.4.1.3224.16.3.4.0"; $sess_data = shell_exec($sess_cmd); list($sessalloc, $sessmax, $sessfailed) = explode("\n", $sess_data); if (!is_file($sessrrd)) { rrdtool_create($sessrrd, " --step 300 \\\n DS:allocate:GAUGE:600:0:3000000 \\\n DS:max:GAUGE:600:0:3000000 \\\n DS:failed:GAUGE:600:0:1000 " . $config['rrd_rra']); } rrdtool_update("{$sessrrd}", "N:{$sessalloc}:{$sessmax}:{$sessfailed}"); $graphs['screenos_sessions'] = TRUE;
function snmp_cache_portName($device, $array) { global $config; $timeout = prep_snmp_setting($device, 'timeout'); $retries = prep_snmp_setting($device, 'retries'); if (!isset($device['transport'])) { $device['transport'] = 'udp'; } $cmd = $config['snmpwalk']; $cmd .= snmp_gen_auth($device); $cmd .= ' -CI -m CISCO-STACK-MIB -O Qs'; $cmd .= mibdir(null); $cmd .= isset($timeout) ? ' -t ' . $timeout : ''; $cmd .= isset($retries) ? ' -r ' . $retries : ''; $cmd .= ' ' . $device['transport'] . ':' . $device['hostname'] . ':' . $device['port'] . ' portName'; $output = trim(external_exec($cmd)); // echo("Caching: portName\n"); foreach (explode("\n", $output) as $entry) { $entry = str_replace('portName.', '', $entry); list($slotport, $portName) = explode('=', $entry, 2); $slotport = trim($slotport); $portName = trim($portName); if ($array[$slotport]['ifIndex']) { $ifIndex = $array[$slotport]['ifIndex']; $array[$slotport]['portName'] = $portName; $array[$ifIndex]['portName'] = $portName; } } return $array; }
<?php if ($device['os_group'] == 'cisco') { $datas = shell_exec($config['snmpbulkwalk'] . ' -M ' . $config['mibdir'] . ' -m CISCO-IP-STAT-MIB -Oqn ' . snmp_gen_auth($device) . ' ' . $device['hostname'] . ' cipMacSwitchedBytes'); // echo("$datas\n"); // echo("done\n"); foreach (explode("\n", $datas) as $data) { list($oid) = explode(' ', $data); $oid = str_replace('.1.3.6.1.4.1.9.9.84.1.2.1.1.4.', '', $oid); list($if, $direction, $a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode('.', $oid); $oid = "{$a_a}.{$a_b}.{$a_c}.{$a_d}.{$a_e}.{$a_f}"; unset($interface); $interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if)); $ah_a = zeropad(dechex($a_a)); $ah_b = zeropad(dechex($a_b)); $ah_c = zeropad(dechex($a_c)); $ah_d = zeropad(dechex($a_d)); $ah_e = zeropad(dechex($a_e)); $ah_f = zeropad(dechex($a_f)); $mac = "{$ah_a}:{$ah_b}:{$ah_c}:{$ah_d}:{$ah_e}:{$ah_f}"; $mac_cisco = "{$ah_a}{$ah_b}.{$ah_c}{$ah_d}.{$ah_e}{$ah_f}"; $mac_cisco = $mac_table[$if][$mac]['ciscomac']; $clean_mac = $mac_table[$if][$mac]['cleanmac']; $ip = $mac_table[$if][$mac]['ip']; if ($ip && $interface) { $new_mac = str_replace(':', '', $mac); // echo($interface['ifDescr'] . " ($if) -> $mac ($oid) -> $ip"); if (dbFetchCell('SELECT COUNT(*) from mac_accounting WHERE port_id = ? AND mac = ?', array($interface['port_id'], $clean_mac))) { // $sql = "UPDATE `mac_accounting` SET `mac` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND `mac` = '$clean_mac'"; // mysql_query($sql); // if (mysql_affected_rows()) { echo(" UPDATED!"); }
/** * Generate an snmp command * * @param string $cmd the snmp command to run, like snmpget * @param array $device the we will be connecting to * @param string $oids the oids to fetch, separated by spaces * @param string $options extra snmp command options, usually this is output options * @param string $mib an additional mib to add to this command * @param string $mibdir a mib directory to search for mibs, usually prepended with + * @return string the fully assembled command, ready to run */ function gen_snmp_cmd($cmd, $device, $oids, $options = null, $mib = null, $mibdir = null) { global $debug; // populate timeout & retries values from configuration $timeout = prep_snmp_setting($device, 'timeout'); $retries = prep_snmp_setting($device, 'retries'); if (!isset($device['transport'])) { $device['transport'] = 'udp'; } $cmd .= snmp_gen_auth($device); $cmd .= " {$options}"; $cmd .= $mib ? " -m {$mib}" : ''; $cmd .= mibdir($mibdir, $device); $cmd .= isset($timeout) ? " -t {$timeout}" : ''; $cmd .= isset($retries) ? " -r {$retries}" : ''; $cmd .= ' ' . $device['transport'] . ':' . $device['hostname'] . ':' . $device['port']; $cmd .= " {$oids}"; if (!$debug) { $cmd .= ' 2>/dev/null'; } return $cmd; }
<?php $oid = $mempool['mempool_index']; // FIXME snmp_get $pool_cmd = $config['snmpget'] . ' -M ' . $config['mibdir'] . ' -m CISCO-ENHANCED-MEMPOOL-MIB -O Uqnv ' . snmp_gen_auth($device) . ' ' . $device['hostname'] . ':' . $device['port']; $pool_cmd .= " cempMemPoolUsed.{$oid} cempMemPoolFree.{$oid} cempMemPoolLargestFree.{$oid}"; $pool_cmd .= " | cut -f 1 -d ' '"; d_echo("SNMP [ {$pool_cmd} ]\n"); $pool = shell_exec($pool_cmd); list($mempool['used'], $mempool['free'], $mempool['largestfree']) = explode("\n", $pool); $mempool['total'] = $mempool['used'] + $mempool['free'];
$ident_key = array_keys($peer_data_tmp); foreach ($peer_data_tmp[$ident_key[0]] as $k => $v) { if (strstr($k, 'cbgpPeer2LocalAddr')) { if ($ip_ver == 'ipv6') { $v = str_replace('"', '', $v); $v = rtrim($v); $v = preg_replace('/(\\S+\\s+\\S+)\\s/', '$1:', $v); $v = strtolower($v); } else { $v = hex_to_ip($v); } } $peer_data .= "{$v}\n"; } } else { $peer_cmd = $config['snmpget'] . ' -M ' . $config['mibdir'] . ' -m BGP4-MIB -OUvq ' . snmp_gen_auth($device) . ' ' . $device['hostname'] . ':' . $device['port'] . ' '; $peer_cmd .= 'bgpPeerState.' . $peer['bgpPeerIdentifier'] . ' bgpPeerAdminStatus.' . $peer['bgpPeerIdentifier'] . ' bgpPeerInUpdates.' . $peer['bgpPeerIdentifier'] . ' bgpPeerOutUpdates.' . $peer['bgpPeerIdentifier'] . ' bgpPeerInTotalMessages.' . $peer['bgpPeerIdentifier'] . ' '; $peer_cmd .= 'bgpPeerOutTotalMessages.' . $peer['bgpPeerIdentifier'] . ' bgpPeerFsmEstablishedTime.' . $peer['bgpPeerIdentifier'] . ' bgpPeerInUpdateElapsedTime.' . $peer['bgpPeerIdentifier'] . ' '; $peer_cmd .= 'bgpPeerLocalAddr.' . $peer['bgpPeerIdentifier'] . ''; $peer_data = trim(`{$peer_cmd}`); } //end if d_echo($peer_data); list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); } elseif ($device['os'] == 'junos') { if (!isset($junos)) { echo "\nCaching Oids..."; foreach ($peer_data_check as $hash => $index) { $peer_ip_snmp = ltrim($index['orig'], '.'); $octets = count(explode(".", $peer_ip_snmp));
<?php // FIXME snmp_ function! $hardware = trim(exec($config['snmpget'] . ' -M ' . $config['mibdir'] . ' -O vqs -m FOUNDRY-SN-AGENT-MIB:FOUNDRY-SN-ROOT-MIB ' . snmp_gen_auth($device) . ' ' . $device['hostname'] . ':' . $device['port'] . ' sysObjectID.0')); $hardware = rewrite_ironware_hardware($hardware); $version = trim(exec($config['snmpget'] . ' -M ' . $config['mibdir'] . ' -O vqs -m FOUNDRY-SN-AGENT-MIB:FOUNDRY-SN-ROOT-MIB ' . snmp_gen_auth($device) . ' ' . $device['hostname'] . ':' . $device['port'] . ' snAgBuildVer.0')); $version = str_replace('V', '', $version); $version = str_replace('"', '', $version); $serial = trim(snmp_get($device, 'snChasSerNum.0', '-Ovq', 'FOUNDRY-SN-AGENT-MIB'), '"');
<?php $serial = ''; // list(,$hardware,) = explode(" ", $hardware); $hardware = $poll_device['sysDescr']; $features = ''; // Filthy hack to get software version. may not work on anything but 585v7 :) $loop = shell_exec($config['snmpget'] . ' -M ' . $config['mibdir'] . ' -Ovq ' . snmp_gen_auth($device) . ' ' . $device['hostname'] . ' ifDescr.101'); if ($loop) { preg_match('@([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)@i', $loop, $matches); $version = $matches[1]; }
<?php // FIXME - this is lame if (!empty($agent_data['app']['mysql'])) { $mysql = $agent_data['app']['mysql']; } else { // Polls MySQL statistics from script via SNMP $mysql_cmd = $config['snmpget'] . ' -m NET-SNMP-EXTEND-MIB -O qv ' . snmp_gen_auth($device) . ' ' . $device['hostname'] . ':' . $device['port']; $mysql_cmd .= ' nsExtendOutputFull.5.109.121.115.113.108'; $mysql = shell_exec($mysql_cmd); } $mysql_rrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/app-mysql-' . $app['app_id'] . '.rrd'; echo ' mysql'; $data = explode("\n", $mysql); $map = array(); foreach ($data as $str) { list($key, $value) = explode(':', $str); $map[$key] = (double) trim($value); // $nstring .= (float)trim($elements[1]).":"; } // General Stats $mapping = array('IDBLBSe' => 'cr', 'IBLFh' => 'ct', 'IBLWn' => 'cu', 'IBLWn' => 'cu', 'SRows' => 'ck', 'SRange' => 'cj', 'SMPs' => 'ci', 'SScan' => 'cl', 'IBIRd' => 'ai', 'IBIWr' => 'aj', 'IBILg' => 'ak', 'IBIFSc' => 'ah', 'IDBRDd' => 'b2', 'IDBRId' => 'b0', 'IDBRRd' => 'b3', 'IDBRUd' => 'b1', 'IBRd' => 'ae', 'IBCd' => 'af', 'IBWr' => 'ag', 'TLIe' => 'b5', 'TLWd' => 'b4', 'IBPse' => 'aa', 'IBPDBp' => 'ac', 'IBPFe' => 'ab', 'IBPMps' => 'ad', 'TOC' => 'bc', 'OFs' => 'b7', 'OTs' => 'b8', 'OdTs' => 'b9', 'IBSRs' => 'ay', 'IBSWs' => 'ax', 'IBOWs' => 'az', 'QCs' => 'c1', 'QCeFy' => 'bu', 'MaCs' => 'bl', 'MUCs' => 'bf', 'ACs' => 'bd', 'AdCs' => 'be', 'TCd' => 'bi', 'Cs' => 'bn', 'IBTNx' => 'a5', 'KRRs' => 'a0', 'KRs' => 'a1', 'KWR' => 'a2', 'KWs' => 'a3', 'QCQICe' => 'bz', 'QCHs' => 'bv', 'QCIs' => 'bw', 'QCNCd' => 'by', 'QCLMPs' => 'bx', 'CTMPDTs' => 'cn', 'CTMPTs' => 'cm', 'CTMPFs' => 'co', 'IBIIs' => 'au', 'IBIMRd' => 'av', 'IBIMs' => 'aw', 'IBILog' => 'al', 'IBISc' => 'am', 'IBIFLg' => 'an', 'IBFBl' => 'aq', 'IBIIAo' => 'ap', 'IBIAd' => 'as', 'IBIAe' => 'at', 'SFJn' => 'cd', 'SFRJn' => 'ce', 'SRe' => 'cf', 'SRCk' => 'cg', 'SSn' => 'ch', 'SQs' => 'b6', 'BRd' => 'cq', 'BSt' => 'cp', 'CDe' => 'c6', 'CIt' => 'c4', 'CISt' => 'ca', 'CLd' => 'c8', 'CRe' => 'c7', 'CRSt' => 'cc', 'CSt' => 'c5', 'CUe' => 'c3', 'CUMi' => 'c9'); $values = array(); unset($fields); foreach ($mapping as $k => $v) { $fields[$k] = isset($map[$v]) ? $map[$v] : -1; } $string = implode(':', $values); if (!is_file($mysql_rrd)) { rrdtool_create($mysql_rrd, '--step 300 DS:IDBLBSe:GAUGE:600:0:125000000000
<?php echo "Polling SNOM device...\n"; // Get SNOM specific version string from silly SNOM location. Silly SNOM! // FIXME - This needs a good cleanup... $cmd = 'snmpget -O qv ' . snmp_gen_auth($device) . ' ' . $device['hostname'] . ':' . $device['port'] . ' 1.3.6.1.2.1.7526.2.4'; $poll_device['sysDescr'] = `{$cmd}`; $poll_device['sysDescr'] = str_replace('-', ' ', $poll_device['sysDescr']); $poll_device['sysDescr'] = str_replace('"', '', $poll_device['sysDescr']); list($hardware, $features, $version) = explode(' ', $poll_device['sysDescr']); // Get data for calls and network from SNOM specific SNMP OIDs. $cmda = 'snmpget -O qv ' . snmp_gen_auth($device) . ' ' . $device['hostname'] . ':' . $device['port'] . ' 1.3.6.1.2.1.7526.2.1.1 1.3.6.1.2.1.7526.2.1.2 1.3.6.1.2.1.7526.2.2.1 1.3.6.1.2.1.7526.2.2.2'; $cmdb = 'snmpget -O qv ' . snmp_gen_auth($device) . ' ' . $device['hostname'] . ':' . $device['port'] . ' 1.3.6.1.2.1.7526.2.5 1.3.6.1.2.1.7526.2.6'; // echo($cmda); $snmpdata = `{$cmda}`; $snmpdatab = `{$cmdb}`; list($rxbytes, $rxpkts, $txbytes, $txpkts) = explode("\n", $snmpdata); list($calls, $registrations) = explode("\n", $snmpdatab); $txbytes = 0 - $txbytes * 8; $rxbytes = 0 - $rxbytes * 8; echo "{$rxbytes}, {$rxpkts}, {$txbytes}, {$txpkts}, {$calls}, {$registrations}"; $rrd_name = 'data'; $rrd_def = array('DS:INOCTETS:COUNTER:600:U:100000000000', 'DS:OUTOCTETS:COUNTER:600:U:10000000000', 'DS:INPKTS:COUNTER:600:U:10000000000', 'DS:OUTPKTS:COUNTER:600:U:10000000000', 'DS:CALLS:COUNTER:600:U:10000000000', 'DS:REGISTRATIONS:COUNTER:600:U:10000000000'); $fields = array('INOCTETS' => $rxbytes, 'OUTOCTETS' => $txbytes, 'INPKTS' => $rxpkts, 'OUTPKTS' => $rxbytes, 'CALLS' => $calls, 'REGISTRATIONS' => $registrations); $tags = compact('rrd_name', 'rrd_def'); data_update($device, 'snom-data', $tags, $fields);
<?php if ($device['os_group'] == "cisco") { echo "Cisco MAC Accounting : "; $datas = shell_exec($config['snmpbulkwalk'] . " -M " . $config['mibdir'] . " -m CISCO-IP-STAT-MIB -Oqn " . snmp_gen_auth($device) . " " . $device['hostname'] . " cipMacSwitchedBytes"); #echo("$datas\n"); #echo("done\n"); foreach (explode("\n", $datas) as $data) { list($oid) = explode(" ", $data); $oid = str_replace(".1.3.6.1.4.1.9.9.84.1.2.1.1.4.", "", $oid); list($if, $direction, $a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(".", $oid); $oid = "{$a_a}.{$a_b}.{$a_c}.{$a_d}.{$a_e}.{$a_f}"; unset($interface); $interface = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device['device_id'], $if)); $ah_a = zeropad(dechex($a_a)); $ah_b = zeropad(dechex($a_b)); $ah_c = zeropad(dechex($a_c)); $ah_d = zeropad(dechex($a_d)); $ah_e = zeropad(dechex($a_e)); $ah_f = zeropad(dechex($a_f)); $mac = "{$ah_a}:{$ah_b}:{$ah_c}:{$ah_d}:{$ah_e}:{$ah_f}"; $mac_cisco = "{$ah_a}{$ah_b}.{$ah_c}{$ah_d}.{$ah_e}{$ah_f}"; $mac_cisco = $mac_table[$if][$mac]['ciscomac']; $clean_mac = $mac_table[$if][$mac]['cleanmac']; $ip = $mac_table[$if][$mac]['ip']; if ($ip && $interface) { $new_mac = str_replace(":", "", $mac); #echo($interface['ifDescr'] . " ($if) -> $mac ($oid) -> $ip"); if (dbFetchCell("SELECT COUNT(*) from mac_accounting WHERE port_id = ? AND mac = ?", array($interface['port_id'], $clean_mac))) { #$sql = "UPDATE `mac_accounting` SET `mac` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND `mac` = '$clean_mac'"; #mysql_query($sql);
if ($device['os'] == 'junos') { // v6 for JunOS via Juniper MIB $peer_ip = ipv62snmp($peer['bgpPeerIdentifier']); if (!isset($junos_v6)) { echo "\nCaching Oids..."; // FIXME - needs moved to function //$peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; $peer_cmd = $config['snmpwalk'] . ' -M ' . $config['mibdir'] . '/junos -m BGP4-V2-MIB-JUNIPER -OUnq -' . $device['snmpver'] . ' ' . snmp_gen_auth($device) . ' ' . $device['hostname'] . ':' . $device['port']; $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6'; foreach (explode("\n", trim(`{$peer_cmd}`)) as $oid) { list($peer_oid) = explode(' ', $oid); $peer_id = explode('.', $peer_oid); $junos_v6[implode('.', array_slice($peer_id, 35))] = implode('.', array_slice($peer_id, 18)); } } $peer_cmd = $config['snmpget'] . ' -M ' . $config['mibdir'] . '/junos -m BGP4-V2-MIB-JUNIPER -OUvq ' . snmp_gen_auth($device); $peer_cmd .= ' -M"' . $config['install_dir'] . '/mibs/junos"'; $peer_cmd .= ' ' . $device['hostname'] . ':' . $device['port']; $peer_cmd .= ' jnxBgpM2PeerState.0.ipv6.' . $junos_v6[$peer_ip]; $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6.' . $junos_v6[$peer_ip]; // Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? $peer_cmd .= ' jnxBgpM2PeerInUpdates.0.ipv6.' . $junos_v6[$peer_ip]; $peer_cmd .= ' jnxBgpM2PeerOutUpdates.0.ipv6.' . $junos_v6[$peer_ip]; $peer_cmd .= ' jnxBgpM2PeerInTotalMessages.0.ipv6.' . $junos_v6[$peer_ip]; $peer_cmd .= ' jnxBgpM2PeerOutTotalMessages.0.ipv6.' . $junos_v6[$peer_ip]; $peer_cmd .= ' jnxBgpM2PeerFsmEstablishedTime.0.ipv6.' . $junos_v6[$peer_ip]; $peer_cmd .= ' jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6.' . $junos_v6[$peer_ip]; $peer_cmd .= ' jnxBgpM2PeerLocalAddr.0.ipv6.' . $junos_v6[$peer_ip]; $peer_cmd .= '|grep -v "No Such Instance"'; d_echo("\n{$peer_cmd}\n"); $peer_data = trim(`{$peer_cmd}`);
<?php $version = preg_replace('/(.+)\\ version\\ (.+)\\ \\(SN:\\ (.+)\\,\\ (.+)\\)/', '\\1||\\2||\\3||\\4', $poll_device['sysDescr']); list($hardware, $version, $serial, $features) = explode('||', $version); $sessrrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/screenos_sessions.rrd'; $sess_cmd = $config['snmpget'] . ' -M ' . $config['mibdir'] . ' -O qv ' . snmp_gen_auth($device) . ' ' . $device['hostname']; $sess_cmd .= ' .1.3.6.1.4.1.3224.16.3.2.0 .1.3.6.1.4.1.3224.16.3.3.0 .1.3.6.1.4.1.3224.16.3.4.0'; $sess_data = shell_exec($sess_cmd); list($sessalloc, $sessmax, $sessfailed) = explode("\n", $sess_data); if (!is_file($sessrrd)) { rrdtool_create($sessrrd, ' --step 300 \\ DS:allocate:GAUGE:600:0:3000000 \\ DS:max:GAUGE:600:0:3000000 \\ DS:failed:GAUGE:600:0:1000 ' . $config['rrd_rra']); } rrdtool_update("{$sessrrd}", "N:{$sessalloc}:{$sessmax}:{$sessfailed}"); $graphs['screenos_sessions'] = true;
<?php $oid = $mempool['mempool_index']; // FIXME snmp_get $pool_cmd = $config['snmpget'] . " -M " . $config['mibdir'] . " -m CISCO-ENHANCED-MEMPOOL-MIB -O Uqnv " . snmp_gen_auth($device) . " " . $device['hostname'] . ":" . $device['port']; $pool_cmd .= " cempMemPoolUsed.{$oid} cempMemPoolFree.{$oid} cempMemPoolLargestFree.{$oid}"; $pool_cmd .= " | cut -f 1 -d ' '"; if ($debug) { echo "SNMP [ {$pool_cmd} ]\n"; } $pool = shell_exec($pool_cmd); list($mempool['used'], $mempool['free'], $mempool['largestfree']) = explode("\n", $pool); $mempool['total'] = $mempool['used'] + $mempool['free'];
function snmp_command($command, $device, $oids, $options, $mib = NULL, $mibdir = NULL) { global $config; // This is compatibility code after refactor in r6306, for keep devices up before DB updated if (get_db_version() < 189) { // FIXME. Remove this in r7000 $device['snmp_version'] = $device['snmpver']; foreach (array('transport', 'port', 'timeout', 'retries', 'community', 'authlevel', 'authname', 'authpass', 'authalgo', 'cryptopass', 'cryptoalgo') as $old_key) { // Convert to new device snmp keys $device['snmp_' . $old_key] = $device[$old_key]; } } // Get the full command path from the config. Chose between bulkwalk and walk. Add max-reps if needed. switch ($command) { case "snmpwalk": if ($device['snmp_version'] == 'v1' || isset($config['os'][$device['os']]['nobulk']) && $config['os'][$device['os']]['nobulk']) { $cmd = $config['snmpwalk']; } else { $cmd = $config['snmpbulkwalk']; if ($config['snmp']['max-rep'] && is_numeric($config['os'][$device['os']]['snmp']['max-rep'])) { $cmd .= ' -Cr' . $config['os'][$device['os']]['snmp']['max-rep']; } } break; case "snmpget": $cmd = $config[$command]; break; case "snmpbulkget": if ($device['snmp_version'] == 'v1' || isset($config['os'][$device['os']]['nobulk']) && $config['os'][$device['os']]['nobulk']) { $cmd = $config['snmpget']; } else { $cmd = $config['snmpbulkget']; if ($config['snmp']['max-rep'] && is_numeric($config['os'][$device['os']]['snmp']['max-rep'])) { $cmd .= ' -Cr' . $config['os'][$device['os']]['snmp']['max-rep']; } } break; default: print_error("THIS SHOULD NOT HAPPEN. PLEASE REPORT TO DEVELOPERS."); return FALSE; } // Set timeout values if set in the database if (is_numeric($device['snmp_timeout']) && $device['snmp_timeout'] > 0) { $snmp_timeout = $device['snmp_timeout']; } else { if (isset($config['snmp']['timeout'])) { $snmp_timeout = $config['snmp']['timeout']; } } if (isset($snmp_timeout)) { $cmd .= " -t " . escapeshellarg($snmp_timeout); } // Set retries if set in the database if (is_numeric($device['snmp_retries']) && $device['snmp_retries'] >= 0) { $snmp_retries = $device['snmp_retries']; } elseif (isset($config['snmp']['retries'])) { $snmp_retries = $config['snmp']['retries']; } if (isset($snmp_retries)) { $cmd .= " -r " . escapeshellarg($snmp_retries); } // If no transport is set in the database, default to UDP. if (empty($device['snmp_transport'])) { $device['snmp_transport'] = 'udp'; } if (!$device['snmp_port']) { $device['snmp_port'] = 161; } // Add the SNMP authentication settings for the device $cmd .= snmp_gen_auth($device); // Hardcode ignoring underscore parsing errors because net-snmp is dumb as a bag of rocks $cmd .= " -Pu "; if ($options) { $cmd .= " " . $options; } if ($mib) { $cmd .= " -m " . $mib; } // Set correct MIB directories based on passed dirs and OS definition if ($mibdir) { $cmd .= " -M " . $mibdir; } else { if (is_array($config['os'][$device['os']]['mib_dirs'])) { // Add device-OS-specific MIB dirs $cmd .= ' -M ' . mib_dirs($config['os'][$device['os']]['mib_dirs']); } else { // Set default Observium MIB dir $cmd .= " -M " . $config['mib_dir']; } } // Add the device URI to the string $cmd .= " " . escapeshellarg($device['snmp_transport']) . ":" . escapeshellarg($device['hostname']) . ":" . escapeshellarg($device['snmp_port']); // Add the OID(s) to the string $cmd .= " " . $oids; // If we're not debugging, direct errors to /dev/null. if (!OBS_DEBUG) { $cmd .= " 2>/dev/null"; } return $cmd; }
<?php if ($device['os_group'] == "unix") { // FIXME snmp_walk # ObserverNMS-style temperature $cmd = $config['snmpwalk'] . " -M " . $config['mib_dir'] . " -m SNMPv2-SMI -Osqn -CI " . snmp_gen_auth($device) . " " . $device['transport'] . ":" . $device['hostname'] . ":" . $device['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"; if ($debug) { echo "{$cmd}\n"; } $oids = shell_exec($cmd); $oids = trim($oids); if ($oids) { echo "Observer-Style "; } foreach (explode("\n", $oids) as $oid) { $oid = trim($oid); if ($oid != "") { // FIXME snmp_get $descr_query = $config['snmpget'] . " -M " . $config['mib_dir'] . " -m SNMPv2-SMI -Osqn " . snmp_gen_auth($device) . " " . $device['transport'] . ':' . $device['hostname'] . ":" . $device['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))); $fulloid = ".1.3.6.1.4.1.2021.7891.{$oid}.101.1"; discover_sensor($valid['sensor'], 'temperature', $device, $fulloid, $oid, 'observium', $descr, '1', '1', NULL, NULL, NULL, NULL, $current); } } }