15 #define HASH_TABLE_SIZE 128
17 static time_t first_time
, last_time
; /* first and last timestamp to show */
18 static time_t last_ltime
, ltime
; /* timestamp of last and current log-line */
19 static uint last_severity
, severity
= -1;
20 static const char *image_url
= "/ninja/application/views/themes/default/icons/16x16";
21 static int reverse_parse_files
;
22 static unsigned long long ltime_skews
, skip
, limit
;
23 static int hide_state_dupes
; /* if set, we hide duplicate state messages */
25 #define EVT_PROCESS (1 << 0)
26 #define EVT_NOTIFY (1 << 1)
27 #define EVT_ALERT (1 << 2)
28 #define EVT_COMMAND (1 << 3)
29 #define EVT_STATE (1 << 4)
30 #define EVT_FLAPPING (1 << 5)
31 #define EVT_DOWNTIME (1 << 6)
32 #define EVT_LROTATE (1 << 7)
33 #define EVT_EHANDLER (1 << 8)
34 #define EVT_START (1 << 9)
35 #define EVT_STOP (1 << 10)
37 #define EVT_HOST (1 << 20)
38 #define EVT_SERVICE (1 << 21)
40 static uint event_filter
= ~0;
41 static int host_state_filter
= -1;
42 static int service_state_filter
= -1;
43 static int statetype_filter
= (1 << HARD_STATE
) | (1 << SOFT_STATE
);
45 #define add_event(string, eventcode) add_code(0, string, eventcode)
46 static struct string_code event_codes
[] = {
47 add_event("Error", EVT_PROCESS
),
48 add_event("Warning", EVT_PROCESS
),
49 add_event("HOST NOTIFICATION", EVT_NOTIFY
| EVT_SERVICE
),
50 add_event("HOST FLAPPING ALERT", EVT_FLAPPING
| EVT_HOST
),
51 add_event("SERVICE NOTIFICATION", EVT_NOTIFY
| EVT_SERVICE
),
52 add_event("SERVICE FLAPPING ALERT", EVT_FLAPPING
| EVT_SERVICE
),
53 add_event("LOG ROTATION", EVT_LROTATE
),
54 add_event("HOST EVENT HANDLER", EVT_EHANDLER
| EVT_HOST
),
55 add_event("SERVICE EVENT HANDLER", EVT_EHANDLER
| EVT_SERVICE
),
56 add_event("LOG VERSION", EVT_PROCESS
),
57 add_event("EXTERNAL COMMAND", EVT_COMMAND
),
59 add_code(5, "HOST ALERT", EVT_ALERT
| EVT_HOST
),
60 add_code(5, "INITIAL HOST STATE", EVT_STATE
| EVT_HOST
),
61 add_code(5, "CURRENT HOST STATE", EVT_STATE
| EVT_HOST
),
62 add_code(6, "SERVICE ALERT", EVT_ALERT
| EVT_SERVICE
),
63 add_code(6, "INITIAL SERVICE STATE", EVT_STATE
| EVT_SERVICE
),
64 add_code(6, "CURRENT SERVICE STATE", EVT_STATE
| EVT_SERVICE
),
65 add_code(3, "HOST DOWNTIME ALERT", EVT_DOWNTIME
| EVT_HOST
),
66 add_code(4, "SERVICE DOWNTIME ALERT", EVT_DOWNTIME
| EVT_SERVICE
),
70 static void print_time_iso8601(struct tm
*t
)
72 printf("[%d-%02d-%02d %02d:%02d:%02d] ",
73 t
->tm_year
+ 1900, t
->tm_mon
+ 1, t
->tm_mday
,
74 t
->tm_hour
, t
->tm_min
, t
->tm_sec
);
77 static void print_time_div_iso8601(struct tm
*t
)
79 printf("%d-%02d-%02d %02d:00 ",
80 t
->tm_year
+ 1900, t
->tm_mon
+ 1, t
->tm_mday
, t
->tm_hour
);
83 static void print_time_duration(struct tm
*t
)
85 printf("[%6lu] ", ltime
- last_ltime
);
88 static void print_time_raw(struct tm
*t
)
90 printf("[%lu] ", ltime
);
95 void (*func
)(struct tm
*);
96 void (*func_div
)(struct tm
*);
97 } time_format_selections
[] = {
98 { "iso8601", print_time_iso8601
, print_time_div_iso8601
},
99 { "raw", print_time_raw
, NULL
},
100 { "duration", print_time_duration
, NULL
},
103 static void (*print_time
)(struct tm
*) = print_time_iso8601
;
104 static void (*print_time_div
)(struct tm
*) = print_time_div_iso8601
;
106 static void parse_time_format(const char *selection
)
110 if (selection
) for (i
= 0; time_format_selections
[i
].name
; i
++) {
111 if (strcasecmp(selection
, time_format_selections
[i
].name
))
113 print_time
= time_format_selections
[i
].func
;
114 print_time_div
= time_format_selections
[i
].func_div
;
118 crash("Illegal timeformat selection: '%s'\n", selection
);
121 static inline void pre_print_mangle_line(struct tm
*t
, char *line
, uint len
)
125 for (i
= 0; i
< len
; i
++) {
130 localtime_r(<ime
, t
);
134 static void print_line_ascii(int type
, struct tm
*t
, char *line
, uint len
)
141 static void print_line_ansi(int type
, struct tm
*t
, char *line
, uint len
)
143 const char *color
= NULL
;
146 case EVT_ALERT
| EVT_HOST
:
147 case EVT_STATE
| EVT_HOST
:
148 if (severity
== HOST_UP
)
154 case EVT_ALERT
| EVT_SERVICE
:
155 case EVT_STATE
| EVT_SERVICE
:
157 case SERVICE_OK
: color
= CLR_GREEN
; break;
158 case SERVICE_WARNING
: color
= CLR_YELLOW
; break;
159 case SERVICE_CRITICAL
: color
= CLR_RED
; break;
160 case SERVICE_UNKNOWN
: color
= CLR_BROWN
; break;
164 case EVT_DOWNTIME
| EVT_HOST
:
165 case EVT_DOWNTIME
| EVT_SERVICE
:
166 color
= CLR_BRIGHT_CYAN
;
169 case EVT_FLAPPING
| EVT_HOST
:
170 case EVT_FLAPPING
| EVT_SERVICE
:
174 case EVT_NOTIFY
| EVT_HOST
:
175 case EVT_NOTIFY
| EVT_SERVICE
:
176 color
= CLR_BRIGHT_RED
;
188 color
= CLR_BRIGHT_MAGENTA
;
191 case EVT_START
: case EVT_STOP
:
192 color
= CLR_BRIGHT_BLUE
;
199 printf("%s%s\n", line
, CLR_RESET
);
207 static void print_time_break(struct tm
*t
)
211 memcpy(&h
, t
, sizeof(h
));
212 h
.tm_min
= h
.tm_sec
= 0;
213 if (reverse_parse_files
) {
214 /* using mktime and localtime_r again here means we never
215 * have to worry about changing date, month or year in
216 * case we overshoot by one */
217 time_t when
= mktime(&h
) + 3600;
218 localtime_r(&when
, &h
);
227 static void print_line_html(int type
, struct tm
*t
, char *line
, uint len
)
229 const char *image
= NULL
;
230 static time_t last_time_break
= 0;
233 case EVT_ALERT
| EVT_HOST
:
234 case EVT_STATE
| EVT_HOST
:
235 if (severity
== HOST_UP
)
236 image
= "shield-ok.png";
238 image
= "shield-critical.png";
241 case EVT_ALERT
| EVT_SERVICE
:
242 case EVT_STATE
| EVT_SERVICE
:
244 case SERVICE_OK
: image
= "shield-ok.png"; break;
245 case SERVICE_WARNING
: image
= "shield-warning.png"; break;
246 case SERVICE_CRITICAL
: image
= "shield-critical.png"; break;
247 case SERVICE_UNKNOWN
: image
= "shield-unknown.png"; break;
251 case EVT_DOWNTIME
| EVT_HOST
:
252 case EVT_DOWNTIME
| EVT_SERVICE
:
253 image
= "scheduled-downtime.png";
256 case EVT_FLAPPING
| EVT_HOST
:
257 case EVT_FLAPPING
| EVT_SERVICE
:
258 image
= "flapping.gif";
261 case EVT_NOTIFY
| EVT_HOST
:
262 case EVT_NOTIFY
| EVT_SERVICE
:
263 image
= "notify-send.png";
267 image
= "command.png";
271 image
= "logrotate.png";
274 case EVT_EHANDLER
| EVT_HOST
:
275 image
= "hostevent.gif";
278 case EVT_EHANDLER
| EVT_SERVICE
:
279 image
= "serviceevent.gif";
292 image
= "shield-info.png";
294 if (last_time_break
!= ltime
/ 3600) {
296 last_time_break
= ltime
/ 3600;
299 printf("<img src=\"%s/%s\" alt=\"%s\" /> ", image_url
, image
, image
);
301 printf("%s<br />\n", line
);
305 static void (*real_print_line
)(int type
, struct tm
*, char *, uint
) = print_line_ascii
;
306 static void print_line(int type
, char *line
, uint len
)
308 static int last_type
= 0;
309 static char *last_line
= NULL
;
310 static uint last_len
= 0;
313 /* are we still skipping? If so, return early */
319 pre_print_mangle_line(&t
, line
, len
);
320 if (print_time
== print_time_duration
) {
321 int cur_severity
= severity
;
323 severity
= last_severity
;
324 real_print_line(last_type
, &t
, last_line
, last_len
);
325 severity
= cur_severity
;
328 last_severity
= severity
;
330 last_line
= strdup(line
);
335 real_print_line(type
, &t
, line
, len
);
338 /* if we've printed all the lines we should, just exit */
346 static int parse_line(char *orig_line
, uint len
)
348 char *ptr
, *colon
, *line
;
350 struct string_code
*sc
;
352 static time_t prev_ltime
= 0;
356 /* ignore empty lines */
360 /* skip obviously bogus lines */
361 if (len
< 12 || *orig_line
!= '[') {
362 warn("line %d; len too short, or line doesn't start with '[' (%s)",
367 ltime
= strtoul(orig_line
+ 1, &ptr
, 10);
368 if (orig_line
+ 1 == ptr
) {
369 crash("Failed to parse log timestamp from '%s'. I can't handle malformed logdata",
374 /* only print lines in the interesting interval */
375 if (ltime
< first_time
|| ltime
> last_time
)
379 * if ltime is less than the previously parsed ltime,
380 * increment the skew count. otherwise, update prev_ltime
381 * so timestamps stay incremental and skews are counted
384 if (ltime
< prev_ltime
) {
390 while (*ptr
== ']' || *ptr
== ' ')
394 len
-= line
- orig_line
;
396 if (!is_interesting(ptr
))
399 if (!(colon
= strchr(ptr
, ':'))) {
400 /* stupid heuristic, but might be good for something,
401 * somewhere, sometime. if nothing else, it should suppress
403 if (!(event_filter
& EVT_PROCESS
))
406 if (is_start_event(ptr
)) {
407 print_line(EVT_START
, line
, len
);
408 } else if (is_stop_event(ptr
)) {
409 print_line(EVT_STOP
, line
, len
);
415 if (!(sc
= get_event_type(ptr
, colon
- ptr
))) {
419 if (sc
->code
== IGNORE_LINE
)
421 if ((sc
->code
& event_filter
) != sc
->code
)
432 nvecs
= vectorize_string(ptr
, sc
->nvecs
);
434 if (nvecs
!= sc
->nvecs
) {
436 warn("Line %d in %s seems to not have all the fields it should",
437 line_no
, cur_file
->path
);
441 for (i
= 0; i
< sc
->nvecs
; i
++) {
443 /* this should never happen */
444 warn("Line %d in %s seems to be broken, or we failed to parse it into a vector",
445 line_no
, cur_file
->path
);
452 case EVT_ALERT
| EVT_HOST
:
453 case EVT_STATE
| EVT_HOST
:
454 hard
= soft_hard(strv
[2]);
455 if (!(statetype_filter
& (1 << hard
)))
457 severity
= parse_host_state(strv
[1]);
458 if (!(host_state_filter
& (1 << severity
)))
460 if (!auth_host_ok(strv
[0]))
462 if (!is_interesting_host(strv
[0]))
464 if (hide_state_dupes
&& !host_has_new_state(strv
[0], severity
, hard
))
469 case EVT_ALERT
| EVT_SERVICE
:
470 case EVT_STATE
| EVT_SERVICE
:
471 hard
= soft_hard(strv
[3]);
472 if (!(statetype_filter
& (1 << hard
)))
474 severity
= parse_service_state(strv
[2]);
475 if (!(service_state_filter
& (1 << severity
)))
477 if (!auth_service_ok(strv
[0], strv
[1]))
479 if (!is_interesting_service(strv
[0], strv
[1]))
481 if (hide_state_dupes
&& !service_has_new_state(strv
[0], strv
[1], severity
, hard
))
486 case EVT_FLAPPING
| EVT_HOST
:
487 case EVT_DOWNTIME
| EVT_HOST
:
488 if (!auth_host_ok(strv
[0]))
490 if (!is_interesting_host(strv
[0]))
494 case EVT_FLAPPING
| EVT_SERVICE
:
495 case EVT_DOWNTIME
| EVT_SERVICE
:
496 if (!auth_service_ok(strv
[0], strv
[1]))
498 if (!is_interesting_service(strv
[0], strv
[1]))
502 case EVT_NOTIFY
| EVT_HOST
:
503 if (!auth_host_ok(strv
[1]))
505 if (!is_interesting_host(strv
[1]))
508 case EVT_NOTIFY
| EVT_SERVICE
:
509 if (!auth_service_ok(strv
[1], strv
[2]))
511 if (!is_interesting_service(strv
[1], strv
[2]))
515 print_line(sc
->code
, line
, len
);
520 * hashes one line from an "interesting"-file. We use (void *)1
521 * to mark this as "present in hash-table" as we have no real
522 * data to lookup but still want hash_find{,2} to return non-NULL
523 * when it finds a match
525 static int hash_one_line(char *line
, uint len
)
527 return add_interesting_object(line
);
530 static int hash_interesting(const char *path
)
534 if (stat(path
, &st
) < 0)
535 crash("failed to stat %s: %s", path
, strerror(errno
));
537 lparse_path(path
, st
.st_size
, hash_one_line
);
542 static void parse_host_state_filter(char *p
)
544 host_state_filter
= 0;
548 host_state_filter
= -1;
551 host_state_filter
|= 1 << HOST_UNREACHABLE
;
554 host_state_filter
|= 1 << HOST_DOWN
;
557 host_state_filter
|= 1 << HOST_UP
;
563 static void parse_service_state_filter(char *p
)
565 service_state_filter
= 0;
569 service_state_filter
= -1;
572 service_state_filter
|= 1 << SERVICE_OK
;
575 service_state_filter
|= 1 << SERVICE_WARNING
;
578 service_state_filter
|= 1 << SERVICE_CRITICAL
;
581 service_state_filter
|= 1 << SERVICE_UNKNOWN
;
586 extern const char *__progname
;
587 __attribute__((__format__(__printf__
, 1, 2)))
588 static void usage(const char *fmt
, ...)
600 printf("usage: %s [options] [logfiles]\n\n", __progname
);
601 printf(" <logfiles> refers to all the nagios logfiles you want to search through\n");
602 printf(" If --nagios-cfg is given or can be inferred no logfiles need to be supplied\n");
603 printf("Options:\n");
604 printf(" --reverse parse (and print) logs in reverse\n");
605 printf(" --help this cruft\n");
606 printf(" --debug print debugging information\n");
607 printf(" --html print html output\n");
608 printf(" --ansi force-colorize the output\n");
609 printf(" --ascii don't colorize the output\n"),
610 printf(" --user=<username> show only logs this user can see\n");
611 printf(" --cgi-cfg=</path/to/cgi.cfg> path to cgi.cfg\n");
612 printf(" --nagios-cfg=</path/to/nagios.cfg> path to nagios.cfg\n");
613 printf(" --object-cache=</path/to/objects.cache> path to objects.cache\n");
614 printf(" --image-url=<image url> url to images. Implies --html\n");
615 printf(" --hide-state-dupes hide duplicate status messages\n");
616 printf(" --hide-flapping hide flapping messages\n");
617 printf(" --hide-downtime hide downtime messages\n");
618 printf(" --hide-process hide process messages\n");
619 printf(" --hide-command hide external command messages\n");
620 printf(" --hide-notifications hide notification messages\n");
621 printf(" --hide-logrotation hide log rotation messages\n");
622 printf(" --hide-initial hide INITIAL and CURRENT states\n");
623 printf(" --hide-all hide all events\n");
624 printf(" --show-ltime-skews print logtime clock skews\n");
625 printf(" --skip=<integer> number of filtered in messages to skip\n");
626 printf(" --limit=<integer> max number of messages to print\n");
627 printf(" --host=<host_name> show log entries for the named host\n");
628 printf(" --service=<hostname;servicedescription> show log entries for the named service\n");
629 printf(" --first=<timestamp> first log-entry to show\n");
630 printf(" --last=<timestamp> last log-entry to show\n");
631 printf(" --state-type=[hard|soft] state-types to show. default is all\n");
632 printf(" --host-states=[*ardu] host-states to show. can be mixed\n");
633 printf(" 'a' and '*' shows 'all'\n");
634 printf(" 'r' shows 'recovery'\n");
635 printf(" 'd' shows 'down'\n");
636 printf(" 'u' shows 'unreachable'\n");
637 printf(" --service-states=[*arwcu] service-states to show. can be mixed\n");
638 printf(" 'a' and '*' shows 'all'\n");
639 printf(" 'r' shows 'recovery'\n");
640 printf(" 'w' shows 'warning'\n");
641 printf(" 'c' shows 'critical'\n");
642 printf(" 'u' shows 'unknown'\n");
643 printf(" --time-format=[");
644 for (i
= 0; time_format_selections
[i
].name
; i
++) {
645 printf("%s", time_format_selections
[i
].name
);
646 if (time_format_selections
[i
+ 1].name
)
649 printf("] set timeformat for log-entries\n");
661 #define show_hide_code(s, opt) { 0, s, sizeof(#s) - 1, opt }
662 int show_hide(char *arg
, char *opt
)
665 uint filter
= 0, show_filter
= 0;
667 if (!prefixcmp(arg
, "--hide"))
669 else if (!prefixcmp(arg
, "--show"))
681 char *comma
= strchr(arg
, ',');
686 * 'filter' must be OR'ed to here, since we only OR or
687 * reverse-AND it once after the loop is done
689 if (!prefixcmp(arg
, "flapping")) {
690 filter
|= EVT_FLAPPING
;
691 show_filter
|= EVT_HOST
| EVT_SERVICE
;
692 } else if (!prefixcmp(arg
, "downtime")) {
693 filter
|= EVT_DOWNTIME
;
694 show_filter
|= EVT_HOST
| EVT_SERVICE
;
695 } else if (!prefixcmp(arg
, "process")) {
696 filter
|= EVT_PROCESS
;
697 } else if (!prefixcmp(arg
, "command")) {
698 filter
|= EVT_COMMAND
;
699 } else if (!prefixcmp(arg
, "notification")) {
700 filter
|= EVT_NOTIFY
;
701 } else if (!prefixcmp(arg
, "logrotat")) {
702 filter
|= EVT_LROTATE
;
703 } else if (!prefixcmp(arg
, "initial")) {
705 show_filter
|= (EVT_HOST
| EVT_SERVICE
);
706 } else if (!prefixcmp(arg
, "all")) {
709 usage("Unknown %s option: %s\n",
710 what
== OPT_SHOW
? "show" : "hide", comma
);
719 if (what
== OPT_SHOW
) {
720 event_filter
|= filter
| show_filter
;
722 event_filter
&= ~filter
;
728 int main(int argc
, char **argv
)
730 int i
, show_ltime_skews
= 0;
731 unsigned long long tot_lines
= 0;
732 const char *nagios_cfg
= NULL
, *cgi_cfg
= NULL
, *object_cache
= NULL
;
734 strv
= calloc(sizeof(char *), MAX_NVECS
);
736 crash("Failed to alloc initial structs");
738 if (isatty(fileno(stdout
))) {
739 real_print_line
= print_line_ansi
;
740 event_filter
&= ~(EVT_LROTATE
| EVT_PROCESS
);
743 for (i
= 1; i
< argc
; i
++) {
744 char *opt
, *arg
= argv
[i
];
745 int arg_len
, eq_opt
= 0;
747 if ((opt
= strchr(arg
, '='))) {
751 else if (i
< argc
- 1) {
755 if (!strcmp(arg
, "--reverse")) {
756 reverse_parse_files
= 1;
759 if (!strcmp(arg
, "--html")) {
760 real_print_line
= print_line_html
;
763 if (!strcmp(arg
, "--ansi")) {
764 real_print_line
= print_line_ansi
;
767 if (!strcmp(arg
, "--ascii")) {
768 real_print_line
= print_line_ascii
;
771 if (!strcmp(arg
, "--debug") || !strcmp(arg
, "-d")) {
775 if (!strcmp(arg
, "--help")) {
779 /* these must come before the more general "show/hide" below */
780 if (!prefixcmp(arg
, "--show-ltime-skews")) {
781 show_ltime_skews
= 1;
784 if (!prefixcmp(arg
, "--hide-state-dupes")) {
785 hide_state_dupes
= 1;
788 if (!prefixcmp(arg
, "--hide") || !prefixcmp(arg
, "--show")) {
789 if (show_hide(arg
, eq_opt
? opt
: NULL
) < 0) {
790 usage("Illegal option for '%s': %s\n", arg
, opt
);
796 if (!prefixcmp(arg
, "--")) {
798 usage("Option '%s' requires an argument\n", arg
);
803 /* options parsed below require arguments */
804 if (!strcmp(arg
, "--user")) {
808 if (!prefixcmp(arg
, "--object-cache")) {
812 if (!strcmp(arg
, "--nagios-cfg")) {
816 if (!strcmp(arg
, "--cgi-cfg")) {
820 if (!strcmp(arg
, "--skip")) {
821 skip
= strtoull(opt
, NULL
, 0);
824 if (!strcmp(arg
, "--limit")) {
825 limit
= strtoull(opt
, NULL
, 0);
828 if (!strcmp(arg
, "--host")) {
829 event_filter
|= EVT_HOST
;
830 add_interesting_object(opt
);
833 if (!strcmp(arg
, "--service")) {
834 event_filter
|= EVT_SERVICE
;
835 add_interesting_object(opt
);
838 if (!strcmp(arg
, "--image-url")) {
839 real_print_line
= print_line_html
;
843 if (!strcmp(arg
, "--interesting") || !strcmp(arg
, "-i")) {
845 usage("%s requires a filename as argument", arg
);
846 hash_interesting(opt
);
849 if (!strcmp(arg
, "--first") || !strcmp(arg
, "--last")) {
853 crash("%s requires a timestamp as argument", arg
);
854 when
= strtoul(opt
, NULL
, 0);
857 if (!strcmp(arg
, "--first"))
863 if (!strcmp(arg
, "--state-type")) {
864 if (!strcasecmp(opt
, "hard"))
865 statetype_filter
= (1 << HARD_STATE
);
866 if (!strcasecmp(opt
, "soft"))
867 statetype_filter
= (1 << SOFT_STATE
);
870 if (!strcmp(arg
, "--host-states")) {
871 event_filter
|= EVT_HOST
;
872 parse_host_state_filter(opt
);
875 if (!strcmp(arg
, "--service-states")) {
876 event_filter
|= EVT_SERVICE
;
877 parse_service_state_filter(opt
);
880 if (!strcmp(arg
, "--time-format")) {
881 parse_time_format(opt
);
885 /* non-argument, so treat as config- or log-file */
886 arg_len
= strlen(arg
);
887 if (arg_len
> 7 && !strcmp(&arg
[arg_len
- 7], "cgi.cfg")) {
889 } else if (!strcmp(&arg
[strlen(arg
) - 10], "nagios.cfg")) {
892 add_naglog_path(arg
);
896 if (limit
&& print_time
== print_time_duration
) {
901 print_interesting_objects();
903 /* fallback for op5 systems */
904 if (auth_get_user() || (!nagios_cfg
&& !num_nfile
)) {
905 struct cfg_comp
*conf
;
907 conf
= cfg_parse_file(cgi_cfg
? cgi_cfg
: "/opt/monitor/etc/cgi.cfg");
910 for (i
= 0; i
< conf
->vars
; i
++) {
911 struct cfg_var
*v
= conf
->vlist
[i
];
912 if (!nagios_cfg
&& !strcmp(v
->key
, "main_config_file")) {
913 nagios_cfg
= strdup(v
->value
);
915 if (!prefixcmp(v
->key
, "authorized_for_")) {
916 auth_parse_permission(v
->key
, v
->value
);
919 cfg_destroy_compound(conf
);
922 crash("Failed to parse cgi.cfg file '%s'\n", cgi_cfg
);
924 if (auth_get_user()) {
925 crash("--user given, but no suitable cgi.cfg file found\n");
930 if (!nagios_cfg
&& !num_nfile
) {
931 nagios_cfg
= "/opt/monitor/etc/nagios.cfg";
934 struct cfg_comp
*conf
;
936 conf
= cfg_parse_file(nagios_cfg
);
938 usage("Failed to parse nagios' main config file '%s'\n", nagios_cfg
);
939 for (i
= 0; i
< conf
->vars
; i
++) {
940 struct cfg_var
*v
= conf
->vlist
[i
];
941 if (!strcmp(v
->key
, "log_file")) {
942 add_naglog_path(v
->value
);
944 if (!strcmp(v
->key
, "log_archive_path")) {
945 add_naglog_path(v
->value
);
947 if (!object_cache
&& !strcmp(v
->key
, "object_cache_file")) {
948 object_cache
= v
->value
;
956 if (auth_get_user() && object_cache
) {
957 auth_init(object_cache
);
960 if (hide_state_dupes
)
963 /* make sure first_time and last_time are set */
964 last_time
= last_time
? last_time
: time(NULL
);
965 first_time
= first_time
? first_time
: 1;
967 /* flip them if the user made an error (common when reverse-importing) */
968 if (last_time
< first_time
) {
969 int temp
= last_time
;
970 last_time
= first_time
;
974 /* make sure we always have last_ltime */
975 last_ltime
= first_time
;
977 if (reverse_parse_files
)
978 qsort(nfile
, num_nfile
, sizeof(*nfile
), nfile_rev_cmp
);
980 qsort(nfile
, num_nfile
, sizeof(*nfile
), nfile_cmp
);
982 for (i
= 0; i
< num_nfile
; i
++) {
983 struct naglog_file
*nf
= &nfile
[i
];
984 time_t last
; /* last possible timestamp in current file */
986 if (reverse_parse_files
)
987 last
= i
? nfile
[i
- 1].first
: time(NULL
);
989 last
= i
+ 1 < num_nfile
? nfile
[i
+ 1].first
: time(NULL
);
991 if (first_time
> last
|| last_time
< nf
->first
) {
996 debug("importing from %s (%lu : %u)\n", nf
->path
, nf
->first
, nf
->cmp
);
997 tot_lines
+= line_no
;
999 lparse_path_real(reverse_parse_files
, nf
->path
, nf
->size
, parse_line
);
1002 if (print_time
== print_time_duration
) {
1003 /* duration should be calculated til the end of the period */
1005 print_line(0, NULL
, 0);
1008 if (show_ltime_skews
) {
1009 printf("%llu ltime skews in %llu lines. %f%%\n",
1010 ltime_skews
, tot_lines
,
1011 ((float)ltime_skews
/ (float)tot_lines
) * 100);
1014 if (warnings
&& debug_level
)
1015 fprintf(stderr
, "Total warnings: %d\n", warnings
);
1017 print_unhandled_events();