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
|
PHP_FUNCTION(nagios_get_status)
{
char *hostkeys[64] = {"host_name", "has_been_checked", "check_execution_time", "check_latency",
"check_type", "current_state", "current_attempt", "state_type",
"last_state_change", "last_time_up", "last_time_down", "last_time_unreachable",
"last_notification", "next_notification", "no_more_notifications",
"current_notification_number", "notifications_enabled", "problem_has_been_acknowledged",
"acknowledgement_type", "active_checks_enabled", "passive_checks_enabled", "last_update"};
int hostkeySize = 22;
char *servicekeys[64] = {"host_name", "service_description", "has_been_checked", "check_execution_time",
"check_latency", "current_state", "state_type", "last_state_change", "last_time_ok",
"last_time_warning", "last_time_unknown", "last_time_critical", "plugin_output",
"last_check", "notifications_enabled", "active_checks_enabled", "passive_checks_enabled",
"problem_has_been_acknowledged", "acknowledgement_type", "last_update", "is_flapping"};
int servicekeySize = 21;
FILE *statusfile;
int buffer_size = 512;
void *bufferptr = malloc(buffer_size + 1);
char * lineptr = (char *) bufferptr;
int linenumber = 0;
int line_size = 0;
char *filename;
int filename_len;
int inSection = 0;
char *sectionType = malloc(buffer_size);
int sectionTypeSize = 0;
char *linekey = malloc(buffer_size);
int linekeySize = 0;
char *lineval = malloc(buffer_size);
int linevalSize = 0;
zval * sectionData;
zval * serviceStatus;
zval * hostStatus;
zval * serviceDescription;
zval **tmp;
char *hostname;
char *servdesc;
int hostnameSize = 0;
int servdescSize = 0;
array_init(serviceStatus);
array_init(hostStatus);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
RETURN_NULL();
}
//php_printf("Hello %s ", filename);
statusfile = fopen(filename, "r");
if (statusfile == NULL)
{
php_printf("Error opening file.");
free(bufferptr);
free(linekey);
free(lineval);
free(sectionType);
RETURN_FALSE;
}
php_printf("|%p|\n", statusfile);
fclose(statusfile);
//free(lineval);
//free(linekey);
//free(sectionType);
}
|