mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
add agent sensor capacity, hddtemp script in agent-local as demo, possibly needs a little more work
git-svn-id: http://www.observium.org/svn/observer/trunk@3213 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
$sensors = dbFetchRows("SELECT * FROM `sensors` WHERE `sensor_class` = ? AND device_id = ? ORDER BY `sensor_index`", array($sensor_class, $device['device_id']));
|
||||
$sensors = dbFetchRows("SELECT * FROM `sensors` WHERE `sensor_class` = ? AND device_id = ? ORDER BY `poller_type`, `sensor_index`", array($sensor_class, $device['device_id']));
|
||||
|
||||
if (count($sensors))
|
||||
{
|
||||
|
@ -116,7 +116,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
|
||||
{
|
||||
global $config, $debug;
|
||||
|
||||
if ($debug) { echo("Discover sensor: $oid, $index, $type, $descr, $precision, $entPhysicalIndex\n"); }
|
||||
if ($debug) { echo("Discover sensor: $oid, $index, $type, $descr, $poller_type, $precision, $entPhysicalIndex\n"); }
|
||||
|
||||
if (is_null($low_warn_limit) || !is_null($warn_limit))
|
||||
{
|
||||
@ -314,9 +314,9 @@ function sensor_limit($class, $current)
|
||||
return $limit;
|
||||
}
|
||||
|
||||
function check_valid_sensors($device, $class, $valid)
|
||||
function check_valid_sensors($device, $class, $valid, $poller_type = 'snmp')
|
||||
{
|
||||
$entries = dbFetchRows("SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class=? AND S.device_id = D.device_id AND D.device_id = ?", array($class, $device['device_id']));
|
||||
$entries = dbFetchRows("SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class=? AND S.device_id = D.device_id AND D.device_id = ? AND S.poller_type = ?", array($class, $device['device_id'], $poller_type));
|
||||
|
||||
if (count($entries))
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
## IPMI
|
||||
## IPMI - We can discover this on poll!
|
||||
if ($ipmi['host'] = get_dev_attrib($device,'ipmi_hostname'))
|
||||
{
|
||||
echo("IPMI : ");
|
||||
|
23
includes/polling/applications/hddtemp.inc.php
Normal file
23
includes/polling/applications/hddtemp.inc.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
global $agent_sensors;
|
||||
|
||||
include_once("includes/discovery/functions.inc.php");
|
||||
|
||||
$disks = explode('||',trim($agent_data['app']['hddtemp'],'|'));
|
||||
|
||||
if (count($disks))
|
||||
{
|
||||
echo "hddtemp: ";
|
||||
foreach ($disks as $disk)
|
||||
{
|
||||
list($blockdevice,$descr,$temperature,$unit) = explode('|',$disk,4);
|
||||
$diskcount++;
|
||||
discover_sensor($valid['sensor'], 'temperature', $device, '', $diskcount, 'hddtemp', "$blockdevice: $descr", '1', '1', NULL, NULL, NULL, NULL, $temperature, 'agent');
|
||||
|
||||
$agent_sensors['temperature']['hddtemp'][$diskcount] = array('description' => "$blockdevice: $descr", 'current' => $temperature, 'index' => $diskcount);
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
?>
|
@ -2,12 +2,14 @@
|
||||
|
||||
function poll_sensor($device, $class, $unit)
|
||||
{
|
||||
global $config, $memcache;
|
||||
global $config, $memcache, $agent_sensors;
|
||||
|
||||
foreach (dbFetchRows("SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ? AND `poller_type` = 'snmp'", array($class, $device['device_id'])) as $sensor)
|
||||
foreach (dbFetchRows("SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ?", array($class, $device['device_id'])) as $sensor)
|
||||
{
|
||||
echo("Checking $class " . $sensor['sensor_descr'] . "... ");
|
||||
echo("Checking (" . $sensor['poller_type'] . ") $class " . $sensor['sensor_descr'] . "... ");
|
||||
|
||||
if ($sensor['poller_type'] == "snmp")
|
||||
{
|
||||
if ($class == "temperature")
|
||||
{
|
||||
for ($i = 0;$i < 5;$i++) # Try 5 times to get a valid temp reading
|
||||
@ -21,6 +23,23 @@ function poll_sensor($device, $class, $unit)
|
||||
} else {
|
||||
$sensor_value = trim(str_replace("\"", "", snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB")));
|
||||
}
|
||||
} else if ($sensor['poller_type'] == "agent")
|
||||
{
|
||||
if (isset($agent_sensors))
|
||||
{
|
||||
$sensor_value = $agent_sensors[$class][$sensor['sensor_type']][$sensor['sensor_index']]['current'];
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "no agent data!\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "unknown poller type!\n";
|
||||
break;
|
||||
}
|
||||
|
||||
if ($sensor_value == -32768) { echo("Invalid (-32768) "); $sensor_value = 0; }
|
||||
|
||||
|
@ -33,10 +33,6 @@ if ($ipmi['host'] = get_dev_attrib($device,'ipmi_hostname'))
|
||||
|
||||
$rrd_file = get_sensor_rrd($device, $ipmisensors);
|
||||
|
||||
## FIXME - sensor name format change 2011/04/26 - remove this in $amount_of_time.
|
||||
## We don't want to reduce performance forever because douchebags don't svn up!
|
||||
$old_rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename($ipmisensors['sensor_class'].'-'.$ipmisensors['sensor_type'].'-'.$ipmisensors['sensor_index'] . ".rrd");
|
||||
|
||||
if (is_file($old_rrd_file))
|
||||
{
|
||||
rename($old_rrd_file, $rrd_file);
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
global $debug;
|
||||
|
||||
if ($device['os_group'] == "unix")
|
||||
{
|
||||
|
||||
echo("Observium UNIX Agent: ");
|
||||
|
||||
### FIXME - this should be in config and overridable in database
|
||||
|
||||
$agent_port='6556';
|
||||
|
||||
$agent_start = utime();
|
||||
@ -36,7 +36,6 @@ if($device['os_group'] == "unix")
|
||||
|
||||
foreach (explode("<<<", $agent_raw) as $section)
|
||||
{
|
||||
|
||||
list($section, $data) = explode(">>>", $section);
|
||||
list($sa, $sb) = explode("-", $section, 2);
|
||||
|
||||
@ -53,15 +52,33 @@ if($device['os_group'] == "unix")
|
||||
}
|
||||
}
|
||||
|
||||
# print_r($agent_data);
|
||||
if ($debug) { print_r($agent_data); }
|
||||
|
||||
include("unix-agent/packages.inc.php");
|
||||
include("unix-agent/munin-plugins.inc.php");
|
||||
|
||||
foreach (array_keys($agent_data) as $key)
|
||||
{
|
||||
if (file_exists("includes/polling/unix-agent/$key.inc.php"))
|
||||
{
|
||||
if ($debug) { echo("Including: unix-agent/$key.inc.php"); }
|
||||
include("unix-agent/$key.inc.php");
|
||||
}
|
||||
}
|
||||
|
||||
foreach (array_keys($agent_data['app']) as $key)
|
||||
{
|
||||
if (file_exists("includes/polling/applications/$key.inc.php"))
|
||||
{
|
||||
if ($debug) { echo("Including: applications/$key.inc.php"); }
|
||||
include("applications/$key.inc.php");
|
||||
}
|
||||
}
|
||||
|
||||
### Processes
|
||||
if (!empty($agent_data['ps']))
|
||||
{
|
||||
echo("\nProcesses: ");
|
||||
echo("Processes: ");
|
||||
foreach (explode("\n", $agent_data['ps']) as $process)
|
||||
{
|
||||
$process = preg_replace("/\((.*),([0-9]*),([0-9]*),([0-9\.]*)\)\ (.*)/", "\\1|\\2|\\3|\\4|\\5", $process);
|
||||
@ -69,6 +86,7 @@ if($device['os_group'] == "unix")
|
||||
$processlist[] = array('user' => $user, 'vsz' => $vsz, 'rss' => $rss, 'pcpu' => $pcpu, 'command' => $command);
|
||||
}
|
||||
#print_r($processlist);
|
||||
echo("\n");
|
||||
}
|
||||
|
||||
### Apache
|
||||
@ -127,6 +145,13 @@ if($device['os_group'] == "unix")
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($agent_sensors))
|
||||
{
|
||||
echo("Sensors: ");
|
||||
check_valid_sensors($device, 'temperature', $valid['sensor'], 'agent');
|
||||
echo("\n");
|
||||
}
|
||||
|
||||
echo("\n");
|
||||
}
|
||||
|
||||
|
@ -134,6 +134,8 @@
|
||||
log_event('Package removed: '.$pkg['name'].' '.$pkg['arch'].' '.$pkg['version']. ($pkg['build'] != '' ? "-".$pkg['build'] : ''), $device, 'package');
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
|
||||
unset($pkg);
|
||||
unset($pkgs_db_id);
|
||||
unset($pkg_c);
|
||||
|
10
scripts/agent-local/hddtemp
Executable file
10
scripts/agent-local/hddtemp
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
# hddtemp sensor readings
|
||||
# needs hddtemp daemon listening on (at least) localhost
|
||||
# requires netcat to be installed and in the path
|
||||
# (c) 2012, Tom Laermans for Observium
|
||||
|
||||
echo '<<<app-hddtemp>>>'
|
||||
nc localhost 7634
|
||||
echo
|
Reference in New Issue
Block a user