-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathigz.php
More file actions
173 lines (136 loc) · 4.18 KB
/
igz.php
File metadata and controls
173 lines (136 loc) · 4.18 KB
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
<?php
/*
* @Programa
* @name: iGZ
* @versao: 0.1
* @Data 10 de Fevereiro de 2017
* @Copyright: Verdanatech Soluções em TI, 2017
* @Author: Halexsandro de Freitas Sales <halexsandro.sales@verdanatech.com>
* --------------------------------------------------------------------------
* LICENSE
*
* iGZ 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.
* iGZ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* If not, see <http://www.gnu.org/licenses/>.
* --------------------------------------------------------------------------
*/
/*
* Abrindo uma sessão:
* é necessário criar um Token para a aplicação, de forma que possa ser utiliza aqui.
* app_token é gerada em "Menu principal > Configurar > Geral > API"
* API_URL é definida de acordo com o caminho do sistema
*
*/
include 'ZABBIX_FRONTEND_DIR/conf/igz.conf.php';
if ($glpi_active == 1){
$passwd=base64_encode($userLogin.":".$passwd);
/*
* Iniciando a sessão com php-curl
*/
$url=$apiURL . "/initSession";
$ch=curl_init($url);
/*
* Passando parâmetros extras para a conexão com o servidor (vide documentação da API do GLPI)
*/
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Basic ' . $passwd,
'App-Token:' . $appToken));
/*
* Forçando o returno da curl em uma string
*/
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
/*
* Baixando session token id e colocando-a em uma variavel
*/
$sessionToken = curl_exec($ch);
$sessionToken = json_decode($sessionToken);
$sessionToken = $sessionToken->session_token;
/*
* Tratamento de variáveis zabbix para a abertura de chamado
*/
/*
* Convertendo parâmetros da linha de comandos em variáveis
*/
for ($i=1; $i < $argc; $i++) {
parse_str($argv[$i]);
}
/*
* Formatando chamado
*/
/*
* Tratanto severidade do evento
*/
switch ($severity) {
case "Not classified":
$severity = 1;
break;
case "Information":
$severity = 2;
break;
case "Warning":
$severity = 3;
break;
case "Average":
$severity = 4;
break;
case "High":
$severity = 5;
break;
case "Disaster":
$severity = 6;
break;
default:
$severity = 4;
}
/*
* Abrindo chamado no GLPI
*/
$post = array(
input => array(
// 'entities_id' => '0',
'name' => "[Verdanatech iGZ] - Ocorrência em " . $hostName,
'content' => "Foi detectado pelo sistema de monitoramento, um problema de ". $triggerName .
" em " . $hostName . "\n. O número desta trigger no Zabbix é " . $triggerId .
" e sua severidade é " . $severity,
'status' => '1',
'priority' => $severity
));
$postEncode = json_encode($post);
$urlTicket=$apiURL . "/Ticket/";
$ch=curl_init($urlTicket);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postEncode);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Session-Token:' . $sessionToken,
'App-Token:' . $appToken,
'Content-Length: ' . strlen($postEncode)
));
curl_setopt($cURL, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$ticket = curl_exec($ch);
/*
* Encerrando conexão curl
*/
curl_close($ch);
}
if ($telegram_active == 1) {
$mensagem = "[Verdanatech iGZ] - Ocorrência em " .$hostName .
" Foi detectado pelo sistema de monitoramento, um problema de " .
$triggerName . " em " . $hostName. ". O número desta trigger no Zabbix é " .
$triggerId . " e sua severidade é $severity. A prioridade deste evento é $severity";
$url="https://api.telegram.org/bot".$telegramBotToken."/sendMessage?chat_id=".$telegramIdUser."&text=".$mensagem;
$ch=curl_init($url);
$telegramMessage=curl_exec($ch);
curl_close($ch);
}
?>