summaryrefslogtreecommitdiffstats
path: root/contrib/check_uptime.c
diff options
context:
space:
mode:
authorEthan Galstad <egalstad@users.sourceforge.net>2002-02-28 06:42:51 (GMT)
committerEthan Galstad <egalstad@users.sourceforge.net>2002-02-28 06:42:51 (GMT)
commit44a321cb8a42d6c0ea2d96a1086a17f2134c89cc (patch)
treea1a4d9f7b92412a17ab08f34f04eec45433048b7 /contrib/check_uptime.c
parent54fd5d7022ff2d6a59bc52b8869182f3fc77a058 (diff)
downloadmonitoring-plugins-44a321cb8a42d6c0ea2d96a1086a17f2134c89cc.tar.gz
Initial revision
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib/check_uptime.c')
-rw-r--r--contrib/check_uptime.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/contrib/check_uptime.c b/contrib/check_uptime.c
new file mode 100644
index 0000000..46a1b82
--- /dev/null
+++ b/contrib/check_uptime.c
@@ -0,0 +1,99 @@
1/******************************************************************************
2 *
3 * CHECK_UPTIME.C
4 *
5 * Program: Uptime plugin for Nagios
6 * License: GPL
7 * Copyright (c) 2000 Teresa Ramanan (teresa@redowl.org)
8 *
9 * Based on CHECK_LOAD.C
10 * Copyright (c) 1999 Felipe Gustavo de Almeida <galmeida@linux.ime.usp.br>
11 *
12 * Last Modified: $Date$
13 *
14 * Command line: CHECK_UPTIME <host_address>
15 *
16 * Description:
17 *
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.
21 *
22 *****************************************************************************/
23
24#include "common/config.h"
25#include "common/common.h"
26#include "common/utils.h"
27#include "common/popen.h"
28
29int main(int argc, char **argv)
30{
31
32 int result;
33 char input_buffer[MAX_INPUT_BUFFER];
34 int ct;
35 int i;
36 char *tok1 = NULL;
37 char *daytok = NULL;
38 char *hrmintok = NULL;
39 char *runstr = NULL;
40 char tempp;
41 char ch;
42 char delim[] = ",";
43
44 if(argc != 2){
45 printf("Incorrect number of arguments supplied\n");
46 printf("\n");
47 print_revision(argv[0],"$Revision$");
48 printf("Copyright (c) 2000 Teresa Ramanan (tlr@redowl.org)\n");
49 printf("\n");
50 printf("Usage: %s <host_address>\n",argv[0]);
51 printf("\n");
52 return STATE_UNKNOWN;
53 }
54
55 child_process = spopen(PATH_TO_UPTIME);
56 if(child_process==NULL){
57 printf("Error opening %s\n",PATH_TO_UPTIME);
58 return STATE_UNKNOWN;
59 }
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);
63 }
64 fgets(input_buffer,MAX_INPUT_BUFFER-1,child_process);
65 i = 0;
66 ct = 0;
67
68 /* Let's mark the end of this string for parsing purposes */
69 input_buffer[strlen(input_buffer)-1]='\0';
70
71 tempp = input_buffer[0];
72 while(ch != '\0'){
73 ch = (&tempp)[i];
74 if (ch == ',') { ct++; }
75 i++;
76 }
77 runstr = input_buffer;
78 tok1 = strsep(&runstr, delim);
79 if (ct > 4) {
80 hrmintok = strsep(&runstr, delim);
81 hrmintok++;
82 daytok = strstr(tok1,"up");
83 }
84 else {
85 hrmintok = strstr(tok1, "up");
86 }
87
88 result = spclose(child_process);
89 if(result){
90 printf("Error code %d returned in %s\n",result,PATH_TO_UPTIME);
91 return STATE_UNKNOWN;
92 }
93 if (hrmintok == NULL) {
94 printf("Problem - unexpected data returned\n");
95 return STATE_UNKNOWN;
96 }
97 printf("%s%s%s\n",(daytok == NULL)?"":daytok,(daytok == NULL)?"":",",hrmintok);
98 return STATE_OK;
99}