mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 08:02:41 +02:00
initial version
This commit is contained in:
@@ -299,8 +299,12 @@ function GetContacts($results) {
|
||||
}
|
||||
}
|
||||
if( is_numeric($result["device_id"]) ) {
|
||||
$tmpa = dbFetchRow("SELECT sysContact FROM devices WHERE device_id = ?",array($result["device_id"]));
|
||||
$contacts[$tmpa["sysContact"]] = "NOC";
|
||||
if( dbFetchCell("SELECT attrib_value FROM devices_attribs WHERE attrib_type = 'override_sysContact_bool' AND device_id = ?",array($result["device_id"])) === "1" ) {
|
||||
$tmpa = dbFetchCell("SELECT attrib_value FROM devices_attribs WHERE attrib_type = 'override_sysContact_string' AND device_id = ?",array($result["device_id"]));
|
||||
} else {
|
||||
$tmpa = dbFetchCell("SELECT sysContact FROM devices WHERE device_id = ?",array($result["device_id"]));
|
||||
}
|
||||
$contacts[$tmpa] = "NOC";
|
||||
$tmpa = dbFetchRows("SELECT user_id FROM devices_perms WHERE access_level >= 0 AND device_id = ?", array($result["device_id"]));
|
||||
foreach( $tmpa as $tmp ) {
|
||||
$uids[$tmp['user_id']] = $tmp['user_id'];
|
||||
|
||||
+28
-5
@@ -561,12 +561,35 @@ function is_valid_hostname($hostname)
|
||||
return ctype_alnum(str_replace('_','',str_replace('-','',str_replace('.','',$hostname))));
|
||||
}
|
||||
|
||||
function add_service($device, $service, $descr)
|
||||
{
|
||||
$insert = array('device_id' => $device['device_id'], 'service_ip' => $device['hostname'], 'service_type' => $service,
|
||||
'service_changed' => array('UNIX_TIMESTAMP(NOW())'), 'service_desc' => $descr, 'service_param' => "", 'service_ignore' => "0");
|
||||
function add_service($device, $service, $descr, $service_ip, $service_param = "", $service_ignore = 0) {
|
||||
|
||||
if (!is_array($device)) {
|
||||
$device = device_by_id_cache($device);
|
||||
}
|
||||
|
||||
if (empty($service_ip)) {
|
||||
$service_ip = $device['hostname'];
|
||||
}
|
||||
|
||||
$insert = array('device_id' => $device['device_id'], 'service_ip' => $service_ip, 'service_type' => $service,
|
||||
'service_changed' => array('UNIX_TIMESTAMP(NOW())'), 'service_desc' => $descr, 'service_param' => $service_param, 'service_ignore' => $service_ignore);
|
||||
|
||||
return dbInsert($insert, 'services');
|
||||
}
|
||||
|
||||
function edit_service($service, $descr, $service_ip, $service_param = "", $service_ignore = 0) {
|
||||
|
||||
if (!is_numeric($service)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$update = array('service_ip' => $service_ip,
|
||||
'service_changed' => array('UNIX_TIMESTAMP(NOW())'),
|
||||
'service_desc' => $descr,
|
||||
'service_param' => $service_param,
|
||||
'service_ignore' => $service_ignore);
|
||||
return dbUpdate($update, 'services', '`service_id`=?', array($service));
|
||||
|
||||
echo dbInsert($insert, 'services');
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1560,6 +1560,10 @@ $config['graph_types']['device']['netstat_snmp_pkt']['section'] = 'netstats';
|
||||
$config['graph_types']['device']['netstat_snmp_pkt']['order'] = '0';
|
||||
$config['graph_types']['device']['netstat_snmp_pkt']['descr'] = 'SNMP Packet Type Statistics';
|
||||
|
||||
$config['graph_types']['device']['netstat_ip_forward']['section'] = 'netstats';
|
||||
$config['graph_types']['device']['netstat_ip_forward']['order'] = '0';
|
||||
$config['graph_types']['device']['netstat_ip_forward']['descr'] = 'IP Forwarding Statistics';
|
||||
|
||||
$config['graph_types']['device']['netstat_tcp']['section'] = 'netstats';
|
||||
$config['graph_types']['device']['netstat_tcp']['order'] = '0';
|
||||
$config['graph_types']['device']['netstat_tcp']['descr'] = 'TCP Statistics';
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
if ($device['os'] == "routeros")
|
||||
{
|
||||
$oids = snmp_walk($device, "mtxrHlActiveFan", "-OsqnU", "MIKROTIK-MIB");
|
||||
if ($debug) { echo($oids."\n"); }
|
||||
if ($oids) echo("MIKROTIK-MIB ");
|
||||
$divisor = 1;
|
||||
$type = "mikrotik";
|
||||
|
||||
foreach (explode("\n", $oids) as $data)
|
||||
{
|
||||
$data = trim($data);
|
||||
if ($data)
|
||||
{
|
||||
list($oid,$descr) = explode(" ", $data,2);
|
||||
$split_oid = explode('.',$oid);
|
||||
$index = $split_oid[count($split_oid)-1];
|
||||
$descr = "Fan " . $index;
|
||||
$oid = ".1.3.6.1.4.1.14988.1.1.3.9." . $index;
|
||||
$fanspeed = snmp_get($device, $oid, "-Oqv") / $divisor;
|
||||
if ($fanspeed > 0)
|
||||
{
|
||||
discover_sensor($valid['sensor'], 'fanspeed', $device, $oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $fanspeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
if ($device['os'] == "routeros")
|
||||
{
|
||||
$oids = snmp_walk($device, "mtxrHlTemperature", "-OsqnU", "MIKROTIK-MIB");
|
||||
if ($debug) { echo($oids."\n"); }
|
||||
if ($oids) echo("MIKROTIK-MIB ");
|
||||
$divisor = 10.0;
|
||||
$type = "mikrotik";
|
||||
|
||||
foreach (explode("\n", $oids) as $data)
|
||||
{
|
||||
$data = trim($data);
|
||||
if ($data)
|
||||
{
|
||||
list($oid,$descr) = explode(" ", $data,2);
|
||||
$split_oid = explode('.',$oid);
|
||||
$index = $split_oid[count($split_oid)-1];
|
||||
$descr = "Temperature " . $index;
|
||||
$oid = ".1.3.6.1.4.1.14988.1.1.3.10." . $index;
|
||||
$temperature = snmp_get($device, $oid, "-Oqv") / $divisor;
|
||||
|
||||
discover_sensor($valid['sensor'], 'temperature', $device, $oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $temperature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
if ($device['os'] == "routeros")
|
||||
{
|
||||
$oids = snmp_walk($device, "mtxrHlVoltage", "-OsqnU", "MIKROTIK-MIB");
|
||||
if ($debug) { echo($oids."\n"); }
|
||||
if ($oids) echo("MIKROTIK-MIB ");
|
||||
$divisor = 10.0;
|
||||
$type = "mikrotik";
|
||||
|
||||
foreach (explode("\n", $oids) as $data)
|
||||
{
|
||||
$data = trim($data);
|
||||
if ($data)
|
||||
{
|
||||
list($oid,$descr) = explode(" ", $data,2);
|
||||
$split_oid = explode('.',$oid);
|
||||
$index = $split_oid[count($split_oid)-1];
|
||||
$descr = "Voltage " . $index;
|
||||
$oid = ".1.3.6.1.4.1.14988.1.1.3.8." . $index;
|
||||
$voltage = snmp_get($device, $oid, "-Oqv") / $divisor;
|
||||
|
||||
discover_sensor($valid['sensor'], 'voltage', $device, $oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $voltage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -229,9 +229,13 @@ function renamehost($id, $new, $source = 'console')
|
||||
|
||||
// FIXME does not check if destination exists!
|
||||
$host = dbFetchCell("SELECT `hostname` FROM `devices` WHERE `device_id` = ?", array($id));
|
||||
rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new");
|
||||
dbUpdate(array('hostname' => $new), 'devices', 'device_id=?', array($id));
|
||||
log_event("Hostname changed -> $new ($source)", $id, 'system');
|
||||
if (rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new") === TRUE) {
|
||||
dbUpdate(array('hostname' => $new), 'devices', 'device_id=?', array($id));
|
||||
log_event("Hostname changed -> $new ($source)", $id, 'system');
|
||||
} else {
|
||||
echo "Renaming of $host failed\n";
|
||||
log_event("Renaming of $host failed", $id, 'system');
|
||||
}
|
||||
}
|
||||
|
||||
function delete_device($id)
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
if ($device['os'] != "Snom")
|
||||
{
|
||||
echo(" IP-FORWARD");
|
||||
|
||||
// Below have more oids, and are in trees by themselves, so we can snmpwalk_cache_oid them
|
||||
|
||||
$oids = array ('ipCidrRouteNumber');
|
||||
|
||||
unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create);
|
||||
$rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-ip_forward.rrd";
|
||||
|
||||
$rrd_create = $config['rrd_rra'];
|
||||
|
||||
foreach ($oids as $oid)
|
||||
{
|
||||
$oid_ds = truncate($oid, 19, '');
|
||||
$rrd_create .= " DS:$oid_ds:GAUGE:600:U:1000000"; // Limit to 1MPPS?
|
||||
$snmpstring .= " IP-FORWARD-MIB::".$oid.".0";
|
||||
}
|
||||
|
||||
$data = snmp_get_multi($device, $snmpstring, "-OQUs", "IP-FORWARD-MIB");
|
||||
|
||||
$rrdupdate = "N";
|
||||
|
||||
foreach ($oids as $oid)
|
||||
{
|
||||
if (is_numeric($data[0][$oid]))
|
||||
{
|
||||
$value = $data[0][$oid];
|
||||
} else {
|
||||
$value = "U";
|
||||
}
|
||||
$rrdupdate .= ":$value";
|
||||
}
|
||||
|
||||
if (isset($data[0]['ipCidrRouteNumber']))
|
||||
{
|
||||
if (!file_exists($rrd_file)) { rrdtool_create($rrd_file, $rrd_create); }
|
||||
rrdtool_update($rrd_file, $rrdupdate);
|
||||
$graphs['netstat_ip_forward'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
unset($oids, $data, $data_array, $oid, $protos, $snmpstring);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
include("netstats-udp.inc.php");
|
||||
include("netstats-icmp.inc.php");
|
||||
include("netstats-snmp.inc.php");
|
||||
include("netstats-ip_forward.inc.php");
|
||||
|
||||
echo("\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user