Move to fixed DS names in MIB-based polling; add script to convert RRDs

This commit is contained in:
Paul Gear
2015-06-24 19:41:53 +10:00
parent f1ab68deed
commit 7752bc0494
4 changed files with 22 additions and 27 deletions

17
contrib/convert-mib-graphs.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
# Script to convert RRDs from the experimental first release of MIB-based polling.
set -e
set -u
for i; do
base=${i%%.rrd}
mv $i $i.old
echo "Processing $i"
rrdtool dump $i.old | sed -e 's|<name>.*</name>|<name>mibval</name>|' > $base.xml
rrdtool restore $base.xml $i
rm -f $base.xml
done
exit 0

View File

@ -16,14 +16,12 @@ $rrd_list = array();
$prefix = rrd_name($device['hostname'], array($subtype, ''), '');
foreach (glob($prefix.'*.rrd') as $filename) {
// find out what * expanded to
$globpart = str_replace($prefix, '', $filename);
// take off the prefix
$instance = substr($globpart, 0, -4);
// take off ".rrd"
$globpart = str_replace($prefix, '', $filename); // take off the prefix
$instance = substr($globpart, 0, -4); // take off ".rrd"
$ds = array();
$mibparts = explode('-', $subtype);
$mibvar = end($mibparts);
$ds['ds'] = name_shorten($mibvar);
$ds['ds'] = 'mibval';
$ds['descr'] = "$mibvar-$instance";
$ds['filename'] = $filename;
$rrd_list[] = $ds;

View File

@ -611,25 +611,6 @@ function d_print_r($var, $no_debug_text = null) {
}
}
/*
* Shorten the name so it works as an RRD data source name (limited to 19 chars by default).
* Substitute for $subst if necessary.
* @return the shortened name
*/
function name_shorten($name, $common = null, $subst = "mibval", $len = 19) {
if ($common !== null) {
// remove common from the beginning of the string, if present
if (strlen($name) > $len && strpos($name, $common) >= 0) {
$newname = str_replace($common, '', $name);
$name = $newname;
}
}
if (strlen($name) > $len) {
$name = $subst;
}
return $name;
}
/*
* @return the name of the rrd file for $host's $extra component
* @param host Host name

View File

@ -828,7 +828,6 @@ function snmp_mib_parse($oid, $mib, $module, $mibdir=null) {
if ($f[1] && $f[1] == 'OBJECT-TYPE') {
$result['object_type'] = $f[0];
$result['shortname'] = str_replace($mib, '', $f[0]);
$result['dsname'] = name_shorten($f[0], $mib);
continue;
}
@ -1081,8 +1080,8 @@ function save_mibs($device, $mibname, $oids, $mibdef, &$graphs) {
$mibdef[$oid]['shortname'],
$index,
),
array('DS:'.$mibdef[$oid]['dsname'].":$type"),
array($mibdef[$oid]['dsname'] => $val)
array("DS:mibval:$type"),
array("mibval" => $val)
);
}
}