feature: Added app_state support for applications #5068 (#6061)

* feature: Added app_state support for applications #5068

* moved schema file 173 -> 174

* Re-arrange code

* added device_id to dbUpdate call

* updated function + missing apps

* Rename 174.sql to 176.sql

* Remove $device, it is unneeded when updating.  Rename update_applications() -> update_application()

* Some apps can return simply 0
This commit is contained in:
Neil Lathwood
2017-03-11 14:39:32 +00:00
committed by Tony Murray
parent af752afb18
commit 66d1006d91
37 changed files with 73 additions and 1 deletions

View File

@@ -11,7 +11,6 @@ if (count($app_rows) > 0) {
echo $app['app_type'].' include missing! ';
}
}
echo "\n";
}

View File

@@ -11,6 +11,7 @@ if (!empty($agent_data['app'][$name])) {
$options = '-O qv';
$oid = 'nsExtendOutputFull.6.97.112.97.99.104.101';
$apache = snmp_get($device, $oid, $options);
update_application($app, $apache);
}
echo ' apache';

View File

@@ -33,6 +33,7 @@ if (!empty($agent_data['app'][$name]) && $app_id > 0) {
$bind = $agent_data['app'][$name];
$bind_parsed = array();
$prefix = '';
update_application($app, $bind);
foreach (explode("\n", $bind) as $line) {
$pattern = '/^\+\+ ([^+]+) \+\+$/';
preg_match($pattern, $line, $matches);

View File

@@ -12,6 +12,7 @@ if (!empty($agent_data['app'][$name])) {
}
list($section, $data) = explode('>', $section);
update_application($app, $section);
if ($section == "poolstats") {
$rrd_def = RrdDefinition::make()
->addDataset('ops', 'GAUGE', 0)

View File

@@ -9,6 +9,7 @@ $mib = 'NET-SNMP-EXTEND-MIB';
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.9.100.104.99.112.115.116.97.116.115';
$dhcpstats = snmp_walk($device, $oid, $options, $mib);
update_application($app, $dhcpstats);
list($dhcp_total,$dhcp_active,$dhcp_expired,$dhcp_released,$dhcp_abandoned,$dhcp_reset,$dhcp_bootp,$dhcp_backup,$dhcp_free) = explode("\n", $dhcpstats);
$rrd_name = array('app', $name, $app_id);

View File

@@ -11,6 +11,7 @@ foreach (explode('|', $agent_data['app'][$name][$app_instance]) as $part) {
$drbd[$stat] = $val;
}
}
update_application($app, $agent_data['app'][$name][$app_instance]);
$rrd_name = array('app', $name, $app_instance);
$rrd_def = RrdDefinition::make()

View File

@@ -29,6 +29,8 @@ $stats = snmp_get($device, $oid, '-Oqv');
echo ' '.$name;
update_application($app, $stats);
list ($frozen, $queue) = explode("\n", $stats);
$rrd_name = array('app', $name, $app_id);

View File

@@ -10,6 +10,7 @@ $mib = 'NET-SNMP-EXTEND-MIB';
$oid = 'nsExtendOutputFull.8.102.97.105.108.50.98.97.110';
$f2b = snmp_walk($device, $oid, $options, $mib);
update_application($app, $f2b);
$bannedStuff = explode("\n", $f2b);
$banned=$bannedStuff[0];

View File

@@ -8,6 +8,7 @@ $options = '-O qv';
$mib = 'NET-SNMP-EXTEND-MIB';
$oid = 'nsExtendOutLine.13.102.98.115.100.110.102.115.99.108.105.101.110.116';
$nfsclient = snmp_walk($device, $oid, $options, $mib);
update_application($app, $nfsclient);
list($getattr, $setattr, $lookup, $readlink, $read, $write, $create, $remove, $rename, $link, $symlink, $mkdir, $rmdir,
$readdir, $rdirplus, $access, $mknod, $fsstat, $fsinfo, $pathconf, $commit, $timedout, $invalid, $xreplies, $retries,

View File

@@ -8,6 +8,7 @@ $options = '-O qv';
$mib = 'NET-SNMP-EXTEND-MIB';
$oid = 'nsExtendOutLine.13.102.98.115.100.110.102.115.115.101.114.118.101.114';
$nfsserver = snmp_walk($device, $oid, $options, $mib);
update_application($app, $nfsserver);
list($getattr, $setattr, $lookup, $readlink, $read, $write, $create, $remove, $rename, $link, $symlink,
$mkdir, $rmdir, $readdir, $rdirplus, $access, $mknod, $fsstat, $fsinfo, $pathconf, $commit, $retfailed,

View File

@@ -6,6 +6,7 @@ $name = 'freeswitch';
$app_id = $app['app_id'];
if (!empty($agent_data[$name])) {
$rawdata = $agent_data[$name];
update_application($app, $rawdata);
} else {
echo "Freeswitch Missing";
return;

View File

@@ -32,6 +32,7 @@ if (!empty($agent_data['app'][$name]) && $app_id > 0) {
echo ' '.$name;
$gpsd = $agent_data['app'][$name];
$gpsd_parsed = array();
update_application($app, $gpsd);
foreach (explode("\n", $gpsd) as $line) {
list ($field, $data) = explode(':', $line);

View File

@@ -8,6 +8,7 @@ $options = '-O qv';
$oid = 'nsExtendOutputFull.11.109.97.105.108.115.99.97.110.110.101.114';
$mailscanner = snmp_get($device, $oid, $options);
update_application($app, $mailscanner);
echo ' mailscanner';

View File

@@ -13,6 +13,7 @@ if (!empty($agent_data['app']['memcached'])) {
$data = reset($result);
}
update_application($app, $data);
echo ' memcached('.$app['app_instance'].')';
$rrd_name = array('app', $name, $app_id);

View File

@@ -14,6 +14,7 @@ if (!empty($agent_data['app'][$name])) {
$mysql = shell_exec($mysql_cmd);
}
update_application($app, $mysql);
echo ' mysql';
// General Stats

View File

@@ -9,6 +9,7 @@ $oid = '.1.3.6.1.4.1.8072.1.3.2.4';
echo ' ' . $name;
$nfsstats = snmp_walk($device, $oid, '-Oqv', 'NET-SNMP-EXTEND-MIB');
update_application($app, $nfsstats);
$rrd_name = array('app', $name, $app_id);
$rrd_def = RrdDefinition::make()

View File

@@ -9,6 +9,7 @@ $oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.7.110.102.115.115.116.97.116';
echo ' ' . $name;
$nfsstats = snmp_walk($device, $oid, '-Oqv', 'NET-SNMP-EXTEND-MIB');
update_application($app, $nfsstats);
$rrd_name = array('app', 'nfs-stats', $app_id);
$rrd_def = RrdDefinition::make()

View File

@@ -10,6 +10,7 @@ if (!empty($agent_data['app'][$name])) {
// Polls nginx statistics from script via SNMP
$nginx = snmp_get($device, 'nsExtendOutputFull.5.110.103.105.110.120', '-Ovq', 'NET-SNMP-EXTEND-MIB');
}
update_application($app, $nginx);
echo ' nginx';

View File

@@ -7,6 +7,7 @@ $name = 'ntp-client';
$app_id = $app['app_id'];
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.10.110.116.112.45.99.108.105.101.110.116';
$ntpclient = snmp_get($device, $oid, '-Oqv');
update_application($app, $ntpclient);
echo ' '.$name;

View File

@@ -7,6 +7,7 @@ $name = 'ntp-server';
$app_id = $app['app_id'];
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.10.110.116.112.45.115.101.114.118.101.114';
$ntpserver_data = snmp_get($device, $oid, '-Oqv');
update_application($app, $ntpserver_data);
list ($stratum, $offset, $frequency, $jitter, $noise, $stability, $uptime, $buffer_recv, $buffer_free, $buffer_used, $packets_drop, $packets_ignore, $packets_recv, $packets_sent) = explode("\n", $ntpserver_data);
echo ' '.$name;

View File

@@ -9,6 +9,7 @@ $options = '-O qv';
$mib = 'NET-SNMP-EXTEND-MIB';
$oid = 'nsExtendOutputFull.6.110.118.105.100.105.97';
$gpus = snmp_walk($device, $oid, $options, $mib);
update_application($app, $gpus);
$gpuArray = explode("\n", $gpus);

View File

@@ -11,6 +11,7 @@ $rrd_name = array('app', $name, $app_id);
$rrd_def = RrdDefinition::make()->addDataset('packages', 'GAUGE', 0);
$osupdates = snmp_get($device, $oid, $options, $mib);
update_application($app, $osupdates);
$fields = array('packages' => $osupdates,);

View File

@@ -9,6 +9,7 @@ $options = '-O qv';
$mib = 'NET-SNMP-EXTEND-MIB';
$oid = 'nsExtendOutputFull.8.112.104.112.102.112.109.115.112';
$phpfpm = snmp_walk($device, $oid, $options, $mib);
update_application($app, $phpfpm);
list($pool,$start_time,$start_since,$accepted_conn,$listen_queue,$max_listen_queue,$listen_queue_len,$idle_processes,
$active_processes,$total_processes,$max_active_processes,$max_children_reached,$slow_requests) = explode("\n", $phpfpm);

View File

@@ -10,6 +10,7 @@ $queueOID = 'nsExtendOutputFull.5.109.97.105.108.113';
$detailOID = 'nsExtendOutputFull.15.112.111.115.116.102.105.120.100.101.116.97.105.108.101.100';
$mailq = snmp_walk($device, $queueOID, $options, $mib);
$detail= snmp_walk($device, $detailOID, $options, $mib);
update_application($app, $mailq);
list($incomingq, $activeq, $deferredq, $holdq) = explode("\n", $mailq);

View File

@@ -8,6 +8,7 @@ $options = '-O qv';
$mib = 'NET-SNMP-EXTEND-MIB';
$oid = 'nsExtendOutputFull.8.112.111.115.116.103.114.101.115';
$postgres = snmp_walk($device, $oid, $options, $mib);
update_application($app, $postgres);
list($backends, $commits, $rollbacks, $read, $hit, $idxscan, $idxtupread, $idxtupfetch, $idxblksread,
$idxblkshit, $seqscan, $seqtupread, $ret, $fetch, $ins, $upd, $del) = explode("\n", $postgres);

View File

@@ -50,6 +50,7 @@ if ($agent_data['app'][$name]) {
}
if (!empty($data)) {
update_application($app, $data);
$ds_list = array(
'all-outqueries' => 'DERIVE',
'answers-slow' => 'DERIVE',

View File

@@ -15,6 +15,7 @@ if ($agent_data['app'][$name]) {
} else {
$powerdns = snmp_get($device, $oid, $options, $mib);
}
update_application($app, $powerdns);
echo ' powerdns';

View File

@@ -53,6 +53,7 @@ if (isset($config['enable_proxmox']) && $config['enable_proxmox'] && !empty($age
}
if ($proxmox) {
update_application($app, $proxmox);
$pmxlines = explode("\n", $proxmox);
$pmxcluster = array_shift($pmxlines);
dbUpdate(

View File

@@ -70,6 +70,7 @@ if ($agent_data['app'][$name]) {
}
}
update_application($app, $data);
$rrd_name = array('app', $name, $app_id);
$rrd_def = RrdDefinition::make()

View File

@@ -10,6 +10,7 @@ $app_id = $app['app_id'];
$options = '-O qv';
$oid = 'nsExtendOutputFull.9.115.104.111.117.116.99.97.115.116';
$shoutcast = snmp_get($device, $oid, $options);
update_application($app, $shoutcast);
echo ' shoutcast';

View File

@@ -46,6 +46,9 @@ $oids=array(
'.1.3.6.1.4.1.3495.1.3.2.2.1.10.60'
);
$returnedoids=snmp_get_multi_oid($device, $oids);
if (is_array($returnedoids)) {
update_application($app, 'Data ok');
}
$memmaxsize = $returnedoids['.1.3.6.1.4.1.3495.1.2.5.1.0'];
$swapmaxsize = $returnedoids['.1.3.6.1.4.1.3495.1.2.5.2.0'];

View File

@@ -29,6 +29,7 @@ use LibreNMS\RRD\RrdDefinition;
$name = 'tinydns';
$app_id = $app['app_id'];
if (!empty($agent_data['app'][$name]) && $app_id > 0) {
update_application($app, $name);
echo ' tinydns';
$rrd_name = array('app', $name, $app_id);
$rrd_def = RrdDefinition::make()

View File

@@ -6,6 +6,7 @@ $name = 'unbound';
$app_id = $app['app_id'];
if (!empty($agent_data['app'][$name])) {
$rawdata = $agent_data['app'][$name];
update_application($app, $rawdata);
} else {
echo "Unbound Missing";
return;

View File

@@ -26,6 +26,7 @@ $name = 'ups-apcups';
$app_id = $app['app_id'];
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.10.117.112.115.45.97.112.99.117.112.115';
$ups_apcups = trim(snmp_get($device, $oid, '-Oqv'), '"');
update_application($app, $ups_apcups);
echo ' '.$name;

View File

@@ -30,6 +30,7 @@ $name = 'ups-nut';
$app_id = $app['app_id'];
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.7.117.112.115.45.110.117.116';
$ups_nut = snmp_get($device, $oid, '-Oqv');
update_application($app, $ups_nut);
// If "extend" (used above) fails, try "exec" support.
// Note, exec always splits outputs on newline, so need to use snmp_walk (not a single SNMP entry!)

View File

@@ -564,3 +564,37 @@ function get_device_oid_limit($device)
return 10;
}
}
/**
* Update the application status and output in the database.
*
* @param array $app app from the db, including app_id
* @param string $response This should be the full output
*/
function update_application($app, $response)
{
if (!is_numeric($app['app_id'])) {
d_echo('$app does not contain app_id, could not update');
return;
}
$data = array(
'app_state' => 'UNKNOWN',
'timestamp' => array('NOW()'),
);
if ($response != '' && $response !== false) {
if (str_contains($response, array(
'Traceback (most recent call last):',
))) {
$data['app_state'] = 'ERROR';
} else {
$data['app_state'] = 'OK';
}
}
if ($data['app_state'] != $app['app_state']) {
$data['app_state_prev'] = $app['app_state'];
}
dbUpdate($data, 'applications', '`app_id` = ?', array($app['app_id']));
}

2
sql-schema/176.sql Normal file
View File

@@ -0,0 +1,2 @@
ALTER TABLE `applications` ADD `timestamp` TIMESTAMP NOT NULL AFTER `app_status`;
ALTER TABLE `applications` ADD `app_state_prev` VARCHAR(32) NOT NULL AFTER `app_state`;