/** * 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; }
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; }
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)); $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; }