-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsiahs.c
67 lines (53 loc) · 1.89 KB
/
siahs.c
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
/*
SIA-HS Alarm Monitoring Service
Copyright (C) Wilco Baan Hofman <[email protected]> 2012
This program 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.
This program 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
/*
* parse_message parses the string portion of the SIA-HS message
* and writes the event to the database.
* It returns nothing.
*/
STATUS parse_siahs_message(TALLOC_CTX *mem_ctx, const char *pkt_prom, const char *orig_message) {
char *message = talloc_strdup(mem_ctx, orig_message);
char *ptr = message;
char *prom = ptr;
char *code;
const configuration *conf = get_conf();
uint8_t i;
NO_MEM_RETURN(message);
/* Grab the first part, the prom */
while (*ptr != '\0' && *ptr != 'N') {
ptr++;
}
*ptr++ = '\0';
/* Grab the second part, SIA code */
code = ptr;
while (*ptr != '\0' && *ptr != ',') {
ptr++;
}
if (*ptr != '\0') *ptr++ = '\0';
/* The remaining ptr contains the human readable description string */
/* Ignore alive! messages */
if (strcmp(code, "alive!") == 0) {
DEBUG(2, "Got keepalive packet from prom %s", prom);
/* FIXME We must update some keepalive status somewhere to generate offline messages */
return ST_OK;
}
/* Dispatch all configured event handlers */
for (i = 0; i < conf->event_handler_cnt; i++) {
conf->event_handlers[i](message, prom, code, ptr);
}
talloc_free(message);
return ST_OK;
}