forked from bitlair/aruba_graphite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.php
62 lines (48 loc) · 1.71 KB
/
common.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
function sendGraphite($field, $value) {
global $graphite_send, $graphite_prefix, $c_name, $fsock;
$send = $graphite_prefix . $c_name . "." . $field . " " . $value . " " . time() . "\n";
if ($graphite_send) {
fwrite($fsock, $send, strlen($send));
}
echo $send;
}
function get_snmp($oid, $type = "Gauge32") {
global $ip, $community;
return $value = sanatize_snmp($type, snmp2_get($ip, $community, $oid));
}
function sanatize_snmp($type, $value) {
switch ($type) {
case "Gauge32":
$value = str_replace("Gauge32: ", "", $value);
break;
case "STRING":
$value = str_replace("\"", "", str_replace("STRING: ", "", $value));
break;
case "INTEGER":
$value = str_replace("INTEGER: ", "", $value);
break;
case "Counter32":
$value = str_replace("Counter32: ", "", $value);
break;
case "Counter64":
$value = str_replace("Counter64: ", "", $value);
break;
}
return $value;
}
function sshexec($shell, $command, $getoutput = true, $escape = "#") {
fwrite($shell, $command . PHP_EOL);
usleep(1500000);
$out = "";
if ($getoutput) {
while ($buf = fgets($shell)) {
$out .= $buf;
if (strpos($buf, $escape) !== false) {
break;
}
}
}
return $out;
}
?>