mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Callback system done - hopefully
This commit is contained in:
34
callback.php
34
callback.php
@@ -18,13 +18,13 @@ include_once($config['install_dir']."/includes/definitions.inc.php");
|
||||
include_once($config['install_dir']."/includes/functions.php");
|
||||
include_once($config['install_dir']."/includes/alerts.inc.php");
|
||||
|
||||
if (dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'") == '') {
|
||||
dbInsert(array('name'=>'uuid','value'=>uniqid()),'callback');
|
||||
}
|
||||
$enabled = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'enabled'");
|
||||
if ($enabled == 1) {
|
||||
|
||||
$uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'");
|
||||
|
||||
if (dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'enabled'") == 1) {
|
||||
if (dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'") == '') {
|
||||
dbInsert(array('name'=>'uuid','value'=>uniqid()),'callback');
|
||||
}
|
||||
$uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'");
|
||||
|
||||
$queries = array(
|
||||
'alert_rules'=>'SELECT COUNT(`severity`) AS `total`,`severity` FROM `alert_rules` WHERE `disabled`=0 GROUP BY `severity`',
|
||||
@@ -34,20 +34,15 @@ if (dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'enabled'") == 1)
|
||||
'bgppeer_state'=>'SELECT COUNT(`bgpPeerState`) AS `total`,`bgpPeerState` FROM `bgpPeers` GROUP BY `bgpPeerState`',
|
||||
'bgppeer_status'=>'SELECT COUNT(`bgpPeerAdminStatus`) AS `total`,`bgpPeerAdminStatus` FROM `bgpPeers` GROUP BY `bgpPeerAdminStatus`',
|
||||
'bills'=>'SELECT COUNT(`bill_type`) AS `total`,`bill_type` FROM `bills` GROUP BY `bill_type`',
|
||||
'bill_ports'=>'SELECT COUNT(`bill_id`) AS `total`,`bill_id`,COUNT(`port_id`) AS `total` FROM `bill_ports` GROUP BY `bill_id`',
|
||||
'cef'=>'SELECT COUNT(`device_id`) AS `total` FROM `cef_switching`',
|
||||
'cisco_asa'=>'SELECT COUNT(`oid`) AS `total`,`oid` FROM `ciscoASA` WHERE `disabled` = 0 GROUP BY `oid`',
|
||||
'mempool'=>'SELECT COUNT(`cmpName`) AS `total`,`cmpName` FROM `cmpMemPool` GROUP BY `cmpName`',
|
||||
'current'=>'SELECT COUNT(`current_type`) AS `total`,`current_type` FROM `current` GROUP BY `current_type`',
|
||||
'dbschema'=>'SELECT `version` FROM `dbSchema`',
|
||||
'graph_types'=>'SELECT COUNT(`device_id`) AS `total`,`graph` FROM `device_graphs` GROUP BY `graph`',
|
||||
'dbschema'=>'SELECT COUNT(`version`) AS `total`, `version` FROM `dbSchema`',
|
||||
'snmp_version'=>'SELECT COUNT(`snmpver`) AS `total`,`snmpver` FROM `devices` GROUP BY `snmpver`',
|
||||
'os'=>'SELECT COUNT(`os`) AS `total`,`os` FROM `devices` GROUP BY `os`',
|
||||
'type'=>'SELECT COUNT(`type`) AS `total`,`type` FROM `devices` GROUP BY `type`',
|
||||
'full_type'=>'SELECT COUNT(`device_id`) AS `total`, CONCAT_WS(', ', `os`,`hardware`,`type`) FROM `devices` GROUP BY `os`,`hardware`,`type`',
|
||||
'device_attribs'=>'SELECT COUNT(`attrib_type`) AS `total`,`attrib_type` FROM `devices_attribs` GROUP BY `attrib_type`',
|
||||
'inventory'=>'SELECT COUNT(`device_id`) AS `total`,`entPhysicalClass` FROM `entPhysical` GROUP BY `entPhysicalClass`',
|
||||
'hrdevice'=>'SELECT COUNT(`device_id`) AS `total`,`hrDeviceType` FROM hrDevice GROUP BY `hrDeviceType`',
|
||||
'ipsec'=>'SELECT COUNT(`device_id`) AS `total` FROM `ipsec_tunnels`',
|
||||
'ipv4_addresses'=>'SELECT COUNT(`ipv4_address_id`) AS `total` FROM `ipv4_addresses`',
|
||||
'ipv4_macaddress'=>'SELECT COUNT(`port_id`) AS `total` FROM ipv4_mac',
|
||||
@@ -55,7 +50,6 @@ if (dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'enabled'") == 1)
|
||||
'ipv6_addresses'=>'SELECT COUNT(`ipv6_address_id`) AS `total` FROM `ipv6_addresses`',
|
||||
'ipv6_networks'=>'SELECT COUNT(`ipv6_network_id`) AS `total` FROM `ipv6_networks`',
|
||||
'xdp'=>'SELECT COUNT(`id`) AS `total`,`protocol` FROM `links` GROUP BY `protocol`',
|
||||
'mempools'=>'SELECT COUNT(`mempool_id`) AS `total`,`mempool_descr` FROM `mempools` GROUP BY `mempool_descr`',
|
||||
'ospf'=>'SELECT COUNT(`device_id`) AS `total`,`ospfVersionNumber` FROM `ospf_instances` GROUP BY `ospfVersionNumber`',
|
||||
'ospf_links'=>'SELECT COUNT(`device_id`) AS `total`,`ospfIfType` FROM `ospf_ports` GROUP BY `ospfIfType`',
|
||||
'arch'=>'SELECT COUNT(`pkg_id`) AS `total`,`arch` FROM `packages` GROUP BY `arch`',
|
||||
@@ -67,7 +61,6 @@ if (dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'enabled'") == 1)
|
||||
'processors'=>'SELECT COUNT(`processor_id`) AS `total`,`processor_type` FROM `processors` GROUP BY `processor_type`',
|
||||
'pseudowires'=>'SELECT COUNT(`pseudowire_id`) AS `total` FROM `pseudowires`',
|
||||
'sensors'=>'SELECT COUNT(`sensor_id`) AS `total`,`sensor_class` FROM `sensors` GROUP BY `sensor_class`',
|
||||
'services'=>'SELECT COUNT(`service_id`) AS `total`,`service_type` FROM `services` GROUP BY `service_type`',
|
||||
'storage'=>'SELECT COUNT(`storage_id`) AS `total`,`storage_type` FROM `storage` GROUP BY `storage_type`',
|
||||
'toner'=>'SELECT COUNT(`toner_id`) AS `total`,`toner_type` FROM `toner` GROUP BY `toner_type`',
|
||||
'vlans'=>'SELECT COUNT(`vlan_id`) AS `total`,`vlan_type` FROM `vlans` GROUP BY `vlan_type`',
|
||||
@@ -96,6 +89,19 @@ if (dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'enabled'") == 1)
|
||||
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
|
||||
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
|
||||
$result = curl_exec($post);
|
||||
} elseif ($enabled == 2) {
|
||||
|
||||
$uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'");
|
||||
$fields = "uuid=$uuid";
|
||||
|
||||
$clear = curl_init();
|
||||
curl_setopt($clear, CURLOPT_URL, 'http://lathwood.co.uk/log/clear.php');
|
||||
curl_setopt($clear, CURLOPT_POST, count($clear));
|
||||
curl_setopt($clear, CURLOPT_POSTFIELDS, $fields);
|
||||
curl_setopt($clear, CURLOPT_RETURNTRANSFER, 1);
|
||||
$result = curl_exec($clear);
|
||||
dbDelete('callback','`name`="uuid"',array());
|
||||
dbUpdate(array('value' => '0'), 'callback', '`name` = "enabled"', array());
|
||||
}
|
||||
|
||||
?>
|
||||
|
15
html/forms/callback-clear.inc.php
Normal file
15
html/forms/callback-clear.inc.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
dbUpdate(array('value' => '2'), 'callback', '`name` = "enabled"', array());
|
23
html/forms/callback-statistics.inc.php
Normal file
23
html/forms/callback-statistics.inc.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
if ($_POST['state'] == 'true') {
|
||||
$state = 1;
|
||||
} elseif ($_POST['state'] == 'false') {
|
||||
$state = 0;
|
||||
} else {
|
||||
$state = 0;
|
||||
}
|
||||
|
||||
dbUpdate(array('value' => $state), 'callback', '`name` = "enabled"', array());
|
@@ -67,10 +67,30 @@ $stat_pw = dbFetchCell("SELECT COUNT(pseudowire_id) FROM `pseudowires`");
|
||||
$stat_vrf = dbFetchCell("SELECT COUNT(vrf_id) FROM `vrfs`");
|
||||
$stat_vlans = dbFetchCell("SELECT COUNT(vlan_id) FROM `vlans`");
|
||||
|
||||
$callback_status = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'enabled'");
|
||||
if ($callback_status == 1) {
|
||||
$stats_checked = 'checked';
|
||||
} else {
|
||||
$stats_checked = '';
|
||||
}
|
||||
$callback = 'Opt in to send anonymous usage statistics to LibreNMS? <input type="checkbox" data-on-text="Yes" data-off-text="No" data-size="mini" name="statistics" '.$stats_checked.'>';
|
||||
|
||||
echo("
|
||||
<div class='table-responsive'>
|
||||
<table class='table table-condensed'>
|
||||
<tr>
|
||||
<td colspan='4'><span class='bg-danger'>$callback</span></td>
|
||||
<tr>");
|
||||
|
||||
if (dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'") != '' && $callback_status != 2) {
|
||||
echo("
|
||||
<tr>
|
||||
<td colspan='4'><button class='btn btn-danger btn-xs' type='submit' name='clear-stats' id='clear-stats'>Clear remote stats</button></td>
|
||||
</tr>
|
||||
");
|
||||
}
|
||||
|
||||
echo("
|
||||
<td><img src='images/icons/device.png' class='optionicon'> <b>Devices</b></td><td align=right>$stat_devices</td>
|
||||
<td><img src='images/icons/port.png' class='optionicon'> <b>Ports</b></td><td align=right>$stat_ports</td>
|
||||
</tr>
|
||||
@@ -175,3 +195,35 @@ echo("
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$("[name='statistics']").bootstrapSwitch('offColor','danger','size','mini');
|
||||
$('input[name="statistics"]').on('switchChange.bootstrapSwitch', function(event, state) {
|
||||
event.preventDefault();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/ajax_form.php',
|
||||
data: { type: "callback-statistics", state: state},
|
||||
dataType: "html",
|
||||
success: function(data){
|
||||
},
|
||||
error:function(){
|
||||
return $("#switch-state").bootstrapSwitch("toggle");
|
||||
}
|
||||
});
|
||||
});
|
||||
$('#clear-stats').click(function(event) {
|
||||
event.preventDefault();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/ajax_form.php',
|
||||
data: { type: "callback-clear"},
|
||||
dataType: "html",
|
||||
success: function(data){
|
||||
location.reload(true);
|
||||
},
|
||||
error:function(){
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user