// compatibility reasons. $port_association_mode = $config['default_port_association_mode']; if ($device['port_association_mode']) { $port_association_mode = get_port_assoc_mode_name($device['port_association_mode']); } // Query known ports and mapping table in order of discovery to make sure // the latest discoverd/polled port is in the mapping tables. $ports_mapped = get_ports_mapped($device['device_id'], true); $ports = $ports_mapped['ports']; // // Rename any old RRD files still named after the previous ifIndex based naming schema. foreach ($ports_mapped['maps']['ifIndex'] as $ifIndex => $port_id) { foreach (array('', '-adsl', '-dot3') as $suffix) { $old_rrd_name = "port-{$ifIndex}{$suffix}.rrd"; $new_rrd_name = getPortRrdName($port_id, ltrim($suffix, '-')); rrd_file_rename($device, $old_rrd_name, $new_rrd_name); } } $ports_found = array(); // New interface detection foreach ($port_stats as $ifIndex => $port) { // Store ifIndex in port entry and prefetch ifName as we'll need it multiple times $port['ifIndex'] = $ifIndex; $ifName = $port['ifName']; // Get port_id according to port_association_mode used for this device $port_id = get_port_id($ports_mapped, $port, $port_association_mode); if (is_port_valid($port, $device)) { echo 'valid'; // Port newly discovered? if (!$ports[$port_id]) { /**
/** * rrdtool backend implementation of data_update * * Tags: * rrd_def array|string: (required) an array of rrd field definitions example: "DS:dataName:COUNTER:600:U:100000000000" * rrd_name array|string: the rrd filename, will be processed with rrd_name() * rrd_oldname array|string: old rrd filename to rename, will be processed with rrd_name() * rrd_step int: rrd step, defaults to 300 * * @param array $device device array * @param string $measurement the name of this measurement (if no rrd_name tag is given, this will be used to name the file) * @param array $tags tags to pass additional info to rrdtool * @param array $fields data values to update */ function rrdtool_data_update($device, $measurement, $tags, $fields) { global $config; $rrd_name = $tags['rrd_name'] ?: $measurement; $step = $tags['rrd_step'] ?: 300; $oldname = $tags['rrd_oldname']; if (!empty($oldname)) { rrd_file_rename($device, $oldname, $rrd_name); } if (isset($tags['rrd_proxmox_name'])) { $pmxvars = $tags['rrd_proxmox_name']; $rrd = proxmox_rrd_name($pmxvars['pmxcluster'], $pmxvars['vmid'], $pmxvars['vmport']); } else { $rrd = rrd_name($device['hostname'], $rrd_name); } if ($tags['rrd_def'] && !rrdtool_check_rrd_exists($rrd)) { $rrd_def = is_array($tags['rrd_def']) ? $tags['rrd_def'] : array($tags['rrd_def']); // add the --step and the rra definitions to the command $newdef = "--step {$step} " . implode(' ', $rrd_def) . $config['rrd_rra']; rrdtool('create', $rrd, $newdef); } rrdtool_update($rrd, $fields); }
function save_mibs($device, $mibname, $oids, $mibdef, &$graphs) { $usedoids = array(); $deviceoids = array(); foreach ($oids as $index => $array) { foreach ($array as $obj => $val) { // build up the device_oid row for saving into the database $numvalue = is_numeric($val) ? $val + 0 : 0; $deviceoids[] = array('device_id' => $device['device_id'], 'oid' => $mibdef[$obj]['oid'] . "." . $index, 'module' => $mibdef[$obj]['module'], 'mib' => $mibdef[$obj]['mib'], 'object_type' => $obj, 'value' => $val, 'numvalue' => $numvalue); $type = oid_rrd_type($obj, $mibdef); if ($type === false) { continue; } $usedoids[$index][$obj] = $val; // if there's a file from the previous version of MIB-based polling, rename it if (rrd_file_exists($device, array($mibname, $mibdef[$obj]['object_type'], $index)) && !rrd_file_exists($device, array($mibname, $mibdef[$obj]['shortname'], $index))) { rrd_file_rename($device, array($mibname, $mibdef[$obj]['object_type'], $index), array($mibname, $mibdef[$obj]['shortname'], $index)); // Note: polling proceeds regardless of rename result } rrd_create_update($device, array($mibname, $mibdef[$obj]['shortname'], $index), array("DS:mibval:{$type}"), array("mibval" => $val)); } } tag_graphs($mibname, $usedoids, $mibdef, $graphs); update_mib_graph_types($mibname, $usedoids, $mibdef, $graphs); // update database $columns = array('device_id', 'oid', 'module', 'mib', 'object_type', 'value', 'numvalue'); update_db_table('device_oids', $columns, 2, $deviceoids); }
function rrdtool_data_update($device, $measurement, $tags, $fields) { global $config; $rrd_name = $tags['rrd_name'] ? $tags['rrd_name'] : $measurement; $step = $tags['rrd_step'] ? $tags['rrd_step'] : 300; $oldname = $tags['rrd_oldname']; if (isset($oldname) && !empty($oldname)) { rrd_file_rename($device, $oldname, $rrd_name); } $rrd = rrd_name($device['hostname'], $rrd_name); if (!is_file($rrd) && $tags['rrd_def']) { $rrd_def = is_array($tags['rrd_def']) ? $tags['rrd_def'] : array($tags['rrd_def']); // add the --step and the rra definitions to the command $newdef = "--step {$step} " . implode(' ', $rrd_def) . $config['rrd_rra']; rrdtool_create($rrd, $newdef); } rrdtool_update($rrd, $fields); }