Skip to content

Commit

Permalink
Hytera repeater support (#4163)
Browse files Browse the repository at this point in the history
  • Loading branch information
zarya authored and laf committed Aug 23, 2016
1 parent 787c4f0 commit 10d7451
Show file tree
Hide file tree
Showing 10 changed files with 2,034 additions and 6 deletions.
Binary file added html/images/os/hytera.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions includes/definitions.inc.php
Expand Up @@ -1993,6 +1993,12 @@
$config['os'][$os]['over'][2]['graph'] = 'device_mempool';
$config['os'][$os]['over'][2]['text'] = 'Memory Usage';

// Hytera repeaters
$os = "hytera";
$config['os'][$os]['text'] = 'Hytera Repeater';
$config['os'][$os]['type'] = 'wireless';
$config['os'][$os]['icon'] = 'hytera';

// Graph Types
require_once $config['install_dir'].'/includes/load_db_graph_types.inc.php';

Expand Down
8 changes: 8 additions & 0 deletions includes/discovery/os/hytera.inc.php
@@ -0,0 +1,8 @@
<?php

if (!$os) {
if (strstr($sysObjectId, '.1.3.6.1.4.1.40297.1.2.1.1.1')) {
$os = "hytera";
}
}

26 changes: 26 additions & 0 deletions includes/discovery/sensors/temperatures/hytera.inc.php
@@ -0,0 +1,26 @@
<?php

if ($device['os'] == "hytera") {
$oids = snmp_walk($device, "rptPaTemprature", "-OsqnU","HYTERA-REPEATER-MIB");
d_echo($oids);
if ($oids !== false) {
echo("HYTERA-REPEATER-MIB ");
}
$divisor = 1;
$type = "hytera";

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 = "PA Temperature " . $index;
$oid = ".1.3.6.1.4.1.40297.1.2.1.2.2." . $index;
$temperature = hytera_h2f(str_replace("\"", "",snmp_get($device, $oid, "-Oqv")),2);

discover_sensor($valid['sensor'], 'temperature', $device, $oid, $index, $type, $descr, $divisor, '1', 0, 0, 70, 75, $temperature);
}
}
}

25 changes: 25 additions & 0 deletions includes/discovery/sensors/voltages/hytera.inc.php
@@ -0,0 +1,25 @@
<?php

if ($device['os'] == "hytera") {
$oids = snmp_walk($device, "rptVoltage", "-OsqnU","HYTERA-REPEATER-MIB");
d_echo($oids);
if ($oids !== false) {
echo("HYTERA-REPEATER-MIB ");
}
$divisor = 1;
$type = "hytera";

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.40297.1.2.1.2.1." . $index;
$voltage = hytera_h2f(str_replace("\"", "",snmp_get($device, $oid, "-OUqnv", "")),2);
discover_sensor($valid['sensor'], 'voltage', $device, $oid, $index, $type, $descr, $divisor, '1', 11.00, 11.5, 14.5, 15, $voltage);
}
}
}

70 changes: 70 additions & 0 deletions includes/functions.php
Expand Up @@ -1453,3 +1453,73 @@ function report_this($message) {
return '<h2>'.$message.' Please <a href="'.$config['project_issues'].'">report this</a> to the '.$config['project_name'].' developers.</h2>';

}//end report_this()

function hytera_h2f($number,$nd)
{
if (strlen(str_replace(" ","",$number)) == 4) {
$hex = '';
for ($i = 0; $i < strlen($number); $i++) {
$byte = strtoupper(dechex(ord($number{$i})));
$byte = str_repeat('0', 2 - strlen($byte)).$byte;
$hex.=$byte." ";
}
$number = $hex;
unset($hex);
}
$r = '';
$y = explode(' ', $number);
foreach ($y as $z) {
$r = $z . '' . $r;
}

$hex = array();
$number = substr($r, 0, -1);
//$number = str_replace(" ", "", $number);
for ($i=0; $i<strlen($number); $i++) {
$hex[]=substr($number,$i,1);
}

$dec = array();
$hexCount = count($hex);
for ($i=0; $i<$hexCount; $i++) {
$dec[]=hexdec($hex[$i]);
}

$binfinal = "";
$decCount = count($dec);
for ($i=0; $i<$decCount; $i++) {
$binfinal.=sprintf("%04d",decbin($dec[$i]));
}

$sign=substr($binfinal,0,1);
$exp=substr($binfinal,1,8);
$exp=bindec($exp);
$exp-=127;
$scibin=substr($binfinal,9);
$binint=substr($scibin,0,$exp);
$binpoint=substr($scibin,$exp);
$intnumber=bindec("1".$binint);

$tmppoint = "";
for ($i=0; $i<strlen($binpoint); $i++) {
$tmppoint[]=substr($binpoint,$i,1);
}

$tmppoint=array_reverse($tmppoint);
$tpointnumber=number_format($tmppoint[0]/2,strlen($binpoint),'.','');

$pointnumber = "";
for ($i=1; $i<strlen($binpoint); $i++) {
$pointnumber=number_format($tpointnumber/2,strlen($binpoint),'.','');
$tpointnumber=$tmppoint[$i+1].substr($pointnumber,1);
}

$floatfinal=$intnumber+$pointnumber;

if ($sign==1) {
$floatfinal=-$floatfinal;
}

return number_format($floatfinal,$nd,'.','');
}

13 changes: 7 additions & 6 deletions includes/polling/functions.inc.php
Expand Up @@ -27,11 +27,11 @@ function poll_sensor($device, $class, $unit) {
if ($class == 'temperature') {
if ($device['os'] == 'netapp') {
include 'includes/polling/temperatures/netapp.inc.php';
}
else if ($device['os'] == 'canopy') {
} elseif ($device['os'] == 'canopy') {
include 'includes/polling/temperatures/canopy.inc.php';
}
else {
} elseif ($device['os'] == 'hytera') {
require_once 'includes/polling/temperatures/hytera.inc.php';
} else {
// Try 5 times to get a valid temp reading
for ($i = 0; $i < 5; $i++) {
d_echo("Attempt $i ");
Expand All @@ -49,8 +49,9 @@ function poll_sensor($device, $class, $unit) {
// end if
}
}//end if
}
else if ($class == 'state') {
} elseif ($class == "voltage" && $device['os'] == 'hytera') {
require_once "includes/polling/voltages/hytera.inc.php";
} elseif ($class == 'state') {
$sensor_value = trim(str_replace('"', '', snmp_walk($device, $sensor['sensor_oid'], '-Oevq', 'SNMPv2-MIB', $mibdir)));
if (!is_numeric($sensor_value)) {
$state_value = dbFetchCell('SELECT `state_value` FROM `state_translations` LEFT JOIN `sensors_to_state_indexes` ON `state_translations`.`state_index_id` = `sensors_to_state_indexes`.`state_index_id` WHERE `sensors_to_state_indexes`.`sensor_id` = ? AND `state_translations`.`state_descr` LIKE ?', array($sensor['sensor_id'], $sensor_value));
Expand Down
3 changes: 3 additions & 0 deletions includes/polling/temperatures/hytera.inc.php
@@ -0,0 +1,3 @@
<?php

$sensor_value = hytera_h2f(str_replace("\"", "",snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "")),2);
4 changes: 4 additions & 0 deletions includes/polling/voltages/hytera.inc.php
@@ -0,0 +1,4 @@
<?php


$sensor_value = hytera_h2f(str_replace("\"", "",snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "")),2);

0 comments on commit 10d7451

Please sign in to comment.