4 * the code in misc.c expects this to be a global variable. Yes, that's
5 * weird, and no I'm not gonna do anything about it right now. it is a
6 * global variable in Nagios and the module is the designated user of
7 * that functionality, so it's not, strictly speaking, necessary.
9 char *config_file
= NULL
;
12 * converts an arbitrarily long string of data into its
13 * hexadecimal representation
15 char *tohex(const unsigned char *data
, int len
)
17 /* number of bufs must be a power of 2 */
18 static char bufs
[4][41], hex
[] = "0123456789abcdef";
23 buf
= bufs
[bufno
& (ARRAY_SIZE(bufs
) - 1)];
24 for (i
= 0; i
< 20 && i
< len
; i
++) {
25 unsigned int val
= *data
++;
26 *buf
++ = hex
[val
>> 4];
27 *buf
++ = hex
[val
& 0xf];
31 return bufs
[bufno
++ & (ARRAY_SIZE(bufs
) - 1)];
35 #define CMD_LAST_CHANGE 2
37 int main(int argc
, char **argv
)
39 unsigned char hash
[20];
41 char *base
, *cmd_string
= NULL
;
43 base
= strrchr(argv
[0], '/');
49 if (!prefixcmp(base
, "oconf.")) {
50 cmd_string
= base
+ strlen("oconf.");
51 if (!strcmp(cmd_string
, "changed")) {
52 cmd
= CMD_LAST_CHANGE
;
53 } else if (!strcmp(cmd_string
, "hash")) {
58 for (i
= 1; i
< argc
; i
++) {
60 if (!prefixcmp(arg
, "--nagios-cfg=")) {
61 config_file
= &arg
[strlen("--nagios-cfg=")];
67 if (!prefixcmp(arg
, "last") || !prefixcmp(arg
, "change")) {
68 cmd
= CMD_LAST_CHANGE
;
71 if (!strcmp(arg
, "sha1") || !strcmp(arg
, "hash")) {
75 if (!prefixcmp(arg
, "list") || !strcmp(arg
, "files")) {
81 config_file
= "/opt/monitor/etc/nagios.cfg";
85 get_config_hash(hash
);
86 printf("%s\n", tohex(hash
, 20));
89 printf("%lu\n", get_last_cfg_change());
93 struct file_list
**sorted_flist
;
94 unsigned int num_files
, i
;
96 sorted_flist
= get_sorted_oconf_files(&num_files
);
100 for (i
= 0; i
< num_files
; i
++) {
101 printf("%s\n", sorted_flist
[i
]->name
);
102 sorted_flist
[i
]->next
= NULL
;
103 file_list_free(sorted_flist
[i
]);