/** * @dataProvider providerTrimQuotes * @group string */ public function testTrimQuotes($string, $result) { $this->assertEquals($result, trim_quotes($string)); }
function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL, $flags = OBS_SNMP_ALL) { $output = 'QUs'; if (is_flag_set(OBS_SNMP_NUMERIC_INDEX, $flags)) { $output .= 'b'; } if (is_flag_set(OBS_SNMP_NUMERIC, $flags)) { $output .= 'n'; } if (is_flag_set(OBS_SNMP_ENUM, $flags)) { $output .= 'e'; } if (is_flag_set(OBS_SNMP_HEX, $flags)) { $output .= 'x'; } $data = snmp_walk($device, $oid, "-O{$output}", $mib, $mibdir, $flags); foreach (explode("\n", $data) as $entry) { list($oid, $value) = explode('=', $entry, 2); $oid = trim($oid); $value = trim_quotes($value, $flags); if (strpos($oid, '"') !== FALSE) { // Example: jnxVpnPwLocalSiteId.l2Circuit."ge-0/1/1.0".621 $oid_part = $oid; $oid_parts = array(); do { if (preg_match('/^"([^"]*)"(?:\\.(.+))?/', $oid_part, $matches)) { // Part with stripes $oid_parts[] = $matches[1]; $oid_part = $matches[2]; // Next part } else { $matches = explode('.', $oid_part, 2); $oid_parts[] = $matches[0]; $oid_part = $matches[1]; // Next part } // print_vars($matches); } while (strlen($oid_part) > 0); // print_vars($oid_parts); $oid = $oid_parts[0]; $first = $oid_parts[1]; $second = $oid_parts[2]; $third = $oid_parts[3]; } else { // Simple, not always correct $oid_parts = explode('.', $oid); $oid = array_shift($oid_parts); $first = array_shift($oid_parts); $second = array_shift($oid_parts); $third = implode('.', $oid_parts); //list($oid, $first, $second, $third) = explode('.', $oid); } print_debug("{$entry} || {$oid} || {$first} || {$second} || {$third}"); if (isset($oid) && isset($first) && isset($second) && isset($third) && is_valid_snmp_value($value)) { $array[$first][$second][$third][$oid] = $value; } } return $array; }