mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
git-svn-id: http://www.observium.org/svn/observer/trunk@3240 61d68cd4-352d-0410-923a-c4978735b2b8
121 lines
4.5 KiB
PHP
Executable File
121 lines
4.5 KiB
PHP
Executable File
<?php
|
|
|
|
// Plugins
|
|
if (!empty($agent_data['munin']))
|
|
{
|
|
echo("Munin Plugins:");
|
|
if ($debug) { print_r($agent_data['munin']); }
|
|
|
|
// Build array of existing plugins
|
|
$plugins_dbq = dbFetchRows("SELECT * FROM `munin_plugins` WHERE `device_id` = ?", array($device['device_id']));
|
|
foreach ($plugins_dbq as $plugin_db)
|
|
{
|
|
$plugins_db[$plugin_db['mplug_type']]['id'] = $plugin_db['mplug_id'];
|
|
}
|
|
|
|
$old_plugins_rrd_dir = $host_rrd . "/plugins";
|
|
$plugins_rrd_dir = $host_rrd . "/munin";
|
|
if (is_dir($old_plugins_rrd_dir) && !is_dir($plugins_rrd_dir)) { rename($old_plugins_dir, $plugins_dir); }
|
|
if (!is_dir($plugins_rrd_dir)) { mkdir($plugins_rrd_dir); echo("Created directory : $plugins_rrd_dir\n"); }
|
|
$plugin = array();
|
|
foreach ($agent_data['munin'] AS $plugin_type => $plugin_data)
|
|
{
|
|
$plugin = array();
|
|
# list($plugin_type, $instance) = explode("_", $plugin_type);
|
|
|
|
# if (!empty($instance))
|
|
# {
|
|
# echo("\nPlugin: $plugin_type ($instance)");
|
|
# $plugin_rrd = $plugins_rrd_dir . "/" . $plugin_type."_".$instance;
|
|
# $plugin_uniq = $plugin_type."_".$instance;
|
|
# } else {
|
|
echo("\nPlugin: $plugin_type");
|
|
$plugin_rrd = $plugins_rrd_dir . "/".$plugin_type;
|
|
$plugin_uniq = $plugin_type."_";
|
|
# }
|
|
|
|
if ($debug) { echo("\n[$plugin_data]\n"); }
|
|
|
|
foreach (explode("\n", $plugin_data) as $line)
|
|
{
|
|
list($key, $value) = explode(" ", $line, 2);
|
|
if (preg_match("/^graph_/", $key))
|
|
{
|
|
list(,$key) = explode("_", $key);
|
|
$plugin['graph'][$key] = $value;
|
|
} else {
|
|
list($metric,$key) = explode(".", $key);
|
|
$plugin['values'][$metric][$key] = $value;
|
|
}
|
|
}
|
|
|
|
if (!is_array($plugins_db[$plugin_type]))
|
|
{
|
|
$insert = array('device_id' => $device['device_id'], 'mplug_type' => $plugin_type,
|
|
'mplug_instance' => ($instance == NULL ? array('NULL') : $instance),
|
|
'mplug_category' => ($plugin['graph']['category'] == NULL ? 'general' : strtolower($plugin['graph']['category'])),
|
|
'mplug_title' => ($plugin['graph']['title'] == NULL ? array('NULL') : $plugin['graph']['title']),
|
|
'mplug_vlabel' => ($plugin['graph']['vlabel'] == NULL ? array('NULL') : $plugin['graph']['vlabel']),
|
|
'mplug_args' => ($plugin['graph']['args'] == NULL ? array('NULL') : $plugin['graph']['args']),
|
|
'mplug_info' => ($plugin['graph']['info'] == NULL ? array('NULL') : $plugin['graph']['info']),
|
|
);
|
|
$mplug_id = dbInsert($insert, 'munin_plugins');
|
|
} else {
|
|
$mplug_id = $plugins_db[$plugin_type]['id'];
|
|
}
|
|
|
|
if ($mplug_id)
|
|
{
|
|
|
|
echo(" ID: $mplug_id");
|
|
|
|
$dbq = dbFetchRows("SELECT * FROM `munin_plugins_ds` WHERE `mplug_id` = ?", array($mplug_id));
|
|
foreach ($dbq as $v)
|
|
{
|
|
$vu = $v['mplug_id']."_".$v['ds_name'];
|
|
$ds_list[$vu] = 1;
|
|
}
|
|
unset($dbq); unset($v);
|
|
|
|
foreach ($plugin['values'] as $name => $data)
|
|
{
|
|
echo(" $name");
|
|
if (empty($data['type'])) { $data['type'] = "GAUGE"; }
|
|
if (empty($data['graph'])) { $data['graph'] = "yes"; }
|
|
if (empty($data['label'])) { $data['label'] = $name; }
|
|
if (empty($data['draw'])) { $data['draw'] = "LINE1.5"; }
|
|
|
|
$cmd = "--step 300 DS:val:".$data['type'].":600:0:U ";
|
|
$cmd .= $config['rrd_rra'];
|
|
$ds_uniq = $mplug_id."_".$name;
|
|
$filename = $plugin_rrd."_".$name.".rrd";
|
|
if (!is_file($filename))
|
|
{
|
|
rrdtool_create($filename, $cmd);
|
|
}
|
|
rrdtool_update($filename,"N:".$data['value']);
|
|
|
|
if (empty($ds_list[$ds_uniq]))
|
|
{
|
|
$insert = array('mplug_id' => $mplug_id, 'ds_name' => $name,
|
|
'ds_type' => $data['type'], 'ds_label' => $data['label'],
|
|
'ds_cdef' => $data['cdef'], 'ds_draw' => $data['draw'],
|
|
'ds_info' => $data['info'], 'ds_extinfo' => $data['extinfo'],
|
|
'ds_min' => $data['min'], 'ds_max' => $data['max'],
|
|
'ds_graph' => $data['graph'], 'ds_negative' => $data['negative'],
|
|
'ds_warning' => $data['warning'], 'ds_critical' => $data['critical'],
|
|
'ds_colour' => $data['colour'], 'ds_sum' => $data['sum'],
|
|
'ds_stack' => $data['stack'], 'ds_line' => $data['line'],
|
|
);
|
|
$ds_id = dbInsert($insert, 'munin_plugins_ds');
|
|
}
|
|
|
|
}
|
|
} else {
|
|
echo("No ID!\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|