1 /******************************************************************************
5 * Program: Uptime plugin for Nagios
7 * Copyright (c) 2000 Teresa Ramanan (teresa@redowl.org)
9 * Based on CHECK_LOAD.C
10 * Copyright (c) 1999 Felipe Gustavo de Almeida <galmeida@linux.ime.usp.br>
12 * Last Modified: $Date$
14 * Command line: CHECK_UPTIME <host_address>
18 * This plugin parses the output from "uptime", tokenizing it with ',' as the
19 * delimiter. Returning only the number of days and/or the hours and minutes
20 * a machine has been up and running.
22 *****************************************************************************/
29 int main(int argc
, char **argv
)
33 char input_buffer
[MAX_INPUT_BUFFER
];
38 char *hrmintok
= NULL
;
45 printf("Incorrect number of arguments supplied\n");
47 print_revision(argv
[0],"$Revision$");
48 printf("Copyright (c) 2000 Teresa Ramanan (tlr@redowl.org)\n");
50 printf("Usage: %s <host_address>\n",argv
[0]);
55 child_process
= spopen(PATH_TO_UPTIME
);
56 if(child_process
==NULL
){
57 printf("Error opening %s\n",PATH_TO_UPTIME
);
60 child_stderr
=fdopen(child_stderr_array
[fileno(child_process
)],"r");
61 if(child_stderr
==NULL
){
62 printf("Could not open stderr for %s\n",PATH_TO_UPTIME
);
64 fgets(input_buffer
,MAX_INPUT_BUFFER
-1,child_process
);
68 /* Let's mark the end of this string for parsing purposes */
69 input_buffer
[strlen(input_buffer
)-1]='\0';
71 tempp
= input_buffer
[0];
74 if (ch
== ',') { ct
++; }
77 runstr
= input_buffer
;
78 tok1
= strsep(&runstr
, delim
);
80 hrmintok
= strsep(&runstr
, delim
);
82 daytok
= strstr(tok1
,"up");
85 hrmintok
= strstr(tok1
, "up");
88 result
= spclose(child_process
);
90 printf("Error code %d returned in %s\n",result
,PATH_TO_UPTIME
);
93 if (hrmintok
== NULL
) {
94 printf("Problem - unexpected data returned\n");
97 printf("%s%s%s\n",(daytok
== NULL
)?"":daytok
,(daytok
== NULL
)?"":",",hrmintok
);