-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitora_bb.php
181 lines (143 loc) · 7.25 KB
/
monitora_bb.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
error_reporting(0);
$arg = $_SERVER['argv'];
$Path_RRD = "/usr/bin/";
$dir_rrd = "/var/www/rrd/";
?>
<?php
##################################################
## INCLUINDO ARQUIVOS DE CONFIGURACAO ##
##################################################
## CONFIGURACAO DE CONEXAO COM MYSQL
include("config/conexao.php");
$conexao = conexao();
##################################################
mysql_select_db(BANCO);
$tabela = "bckbone";
define(TabelaServico,"SwitchService");
if ($arg == NULL)
{
echo "ERRO: FALTOU INFORMAR O GRUPO!!!\n";
exit;
}
$sql = "SELECT DISTINCT community, host FROM $tabela WHERE uf='$arg[1]'";
if ($arg[1] == "AP") $sql = "SELECT DISTINCT community_dest, host_dest FROM $tabela WHERE uf='$arg[1]'";
$consulta = mysql_query($sql) or die ("ERRO: ". mysql_error()."\n");
list($C, $H) = mysql_fetch_row($consulta);
$sysName = shell_exec("snmpget -Ov -t 1 -r 1 -c $C -v 1 $H .1.3.6.1.2.1.1.5.0");
$sql = "SELECT cod_int, host, community, num_int FROM $tabela WHERE uf='$arg[1]' AND IfStatus='UP' ORDER BY num_int";
if ($arg[1] == "AP") $sql = "SELECT cod_int, host_dest, community_dest, num_int_dest FROM $tabela WHERE uf='$arg[1]' AND IfStatus='UP' ORDER BY num_int";
$consulta = mysql_query($sql);
while ( list ($cod_int, $host, $community, $num_int) = mysql_fetch_array($consulta,MYSQL_NUM))
{
echo "$community - $host - $num_int";
$com = "snmpget -Ov -t 1 -r 1 -c $community -v 1 $host .1.3.6.1.2.1.2.2.1.10.$num_int .1.3.6.1.2.1.2.2.1.16.$num_int";
list ($In, $Out) = explode("\n", shell_exec($com));
$InOctets = snmp($In);
$OutOctets = snmp($Out);
if ($arg[1] == "AP")
{
$TempOctets = $InOctets;
$InOctets = $OutOctets;
$OutOctets = $TempOctets;
}
if($InOctets || $OutOctets)
{
$arq_rrd = $dir_rrd . $cod_int . '.rrd';
if (!file_exists($arq_rrd))
create_rrd($arq_rrd);
update_rrd($arq_rrd, $InOctets, $OutOctets);
}
}
function snmp($resp)
{
$resp = strstr($resp, ':');
$resp = str_replace(":", "", $resp);
return (trim($resp));
}
function update_rrd($arq_rrd, $in, $out)
{
global $Path_RRD;
$data = date('U');
$insert = $Path_RRD . "rrdtool update $arq_rrd $data:$in:$out";
shell_exec($insert);
}
function create_rrd($arq_rrd)
{
global $Path_RRD;
$create = $Path_RRD . "rrdtool create $arq_rrd --step 60 " .
"DS:ds0:COUNTER:120:0:125000000 " .
"DS:ds1:COUNTER:120:0:125000000 " .
"RRA:AVERAGE:0.5:1:4320 " .
"RRA:AVERAGE:0.5:5:2016 " .
"RRA:AVERAGE:0.5:20:2232 " .
"RRA:AVERAGE:0.5:90:2976 " .
"RRA:AVERAGE:0.5:360:1460 " .
"RRA:AVERAGE:0.5:1440:730 " .
"RRA:MAX:0.5:1:4320 " .
"RRA:MAX:0.5:5:2016 " .
"RRA:MAX:0.5:20:2232 " .
"RRA:MAX:0.5:90:2976 " .
"RRA:MAX:0.5:360:1460 " .
"RRA:MAX:0.5:1440:730"
;
shell_exec($create);
}
function SwitchHabilitado($maq)
{
$update = "UPDATE " . TabelaServico . " " .
"SET desabilitado='0'
WHERE equipamento='$maq'
";
mysql_query($update);
}
function SwitchDesabilitado($maq)
{
$select = "
SELECT desabilitado
FROM " . TabelaServico . " " .
"WHERE equipamento='$maq'
";
$consulta = mysql_query($select);
list ($desabilitado) = mysql_fetch_row($consulta);
if($desabilitado==0)
{
echo ">>> EQUIPAMENTO $maq: INEXISTENTE, NAO RESPONDE OU NAO POSSUI HOSTNAME ! ! !\n";
$update =
"UPDATE " . TabelaServico . " " .
"SET desabilitado='1'
WHERE equipamento='$maq'
";
mysql_query($update);
}
elseif($desabilitado>=30)
{
$para = "[email protected]";
$assunto = "Probelmas Switch $maq";
$mensagem = "DIPRO - " . date('d:m:Y H:i') . "\n" .
"AVISO!\n\n".
"Equipamento $maq\n nao esta monitorando"
;
$headers = 'De: Mandacaru <system>';
mail($para, $assunto, $mensagem, $headers);
$update =
"UPDATE " . TabelaServico . " " .
"SET desabilitado='0'
WHERE equipamento='$maq'
";
mysql_query($update);
}
else
{
$desabilitado++;
$update =
"UPDATE " . TabelaServico . " " .
"SET desabilitado='$desabilitado'
WHERE equipamento='$maq'
";
mysql_query($update);
}
exit;
}
mysql_close();
?>