summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_time.c59
1 files changed, 28 insertions, 31 deletions
diff --git a/plugins/check_time.c b/plugins/check_time.c
index cf17b22..7d0cc2e 100644
--- a/plugins/check_time.c
+++ b/plugins/check_time.c
@@ -61,10 +61,6 @@ static void print_help(void);
61void print_usage(void); 61void print_usage(void);
62 62
63int main(int argc, char **argv) { 63int main(int argc, char **argv) {
64 int sd;
65 int result = STATE_UNKNOWN;
66 time_t conntime;
67
68 setlocale(LC_ALL, ""); 64 setlocale(LC_ALL, "");
69 bindtextdomain(PACKAGE, LOCALEDIR); 65 bindtextdomain(PACKAGE, LOCALEDIR);
70 textdomain(PACKAGE); 66 textdomain(PACKAGE);
@@ -82,11 +78,13 @@ int main(int argc, char **argv) {
82 alarm(socket_timeout); 78 alarm(socket_timeout);
83 time(&start_time); 79 time(&start_time);
84 80
81 int socket;
82 int result = STATE_UNKNOWN;
85 /* try to connect to the host at the given port number */ 83 /* try to connect to the host at the given port number */
86 if (use_udp) { 84 if (use_udp) {
87 result = my_udp_connect(server_address, server_port, &sd); 85 result = my_udp_connect(server_address, server_port, &socket);
88 } else { 86 } else {
89 result = my_tcp_connect(server_address, server_port, &sd); 87 result = my_tcp_connect(server_address, server_port, &socket);
90 } 88 }
91 89
92 if (result != STATE_OK) { 90 if (result != STATE_OK) {
@@ -100,7 +98,7 @@ int main(int argc, char **argv) {
100 } 98 }
101 99
102 if (use_udp) { 100 if (use_udp) {
103 if (send(sd, "", 0, 0) < 0) { 101 if (send(socket, "", 0, 0) < 0) {
104 if (check_critical_time) 102 if (check_critical_time)
105 result = STATE_CRITICAL; 103 result = STATE_CRITICAL;
106 else if (check_warning_time) 104 else if (check_warning_time)
@@ -112,10 +110,10 @@ int main(int argc, char **argv) {
112 } 110 }
113 111
114 /* watch for the connection string */ 112 /* watch for the connection string */
115 result = recv(sd, (void *)&raw_server_time, sizeof(raw_server_time), 0); 113 result = recv(socket, (void *)&raw_server_time, sizeof(raw_server_time), 0);
116 114
117 /* close the connection */ 115 /* close the connection */
118 close(sd); 116 close(socket);
119 117
120 /* reset the alarm */ 118 /* reset the alarm */
121 time(&end_time); 119 time(&end_time);
@@ -134,7 +132,7 @@ int main(int argc, char **argv) {
134 132
135 result = STATE_OK; 133 result = STATE_OK;
136 134
137 conntime = (end_time - start_time); 135 time_t conntime = (end_time - start_time);
138 if (check_critical_time && conntime > critical_time) 136 if (check_critical_time && conntime > critical_time)
139 result = STATE_CRITICAL; 137 result = STATE_CRITICAL;
140 else if (check_warning_time && conntime > warning_time) 138 else if (check_warning_time && conntime > warning_time)
@@ -165,9 +163,6 @@ int main(int argc, char **argv) {
165 163
166/* process command-line arguments */ 164/* process command-line arguments */
167int process_arguments(int argc, char **argv) { 165int process_arguments(int argc, char **argv) {
168 int c;
169
170 int option = 0;
171 static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, 166 static struct option longopts[] = {{"hostname", required_argument, 0, 'H'},
172 {"warning-variance", required_argument, 0, 'w'}, 167 {"warning-variance", required_argument, 0, 'w'},
173 {"critical-variance", required_argument, 0, 'c'}, 168 {"critical-variance", required_argument, 0, 'c'},
@@ -183,26 +178,28 @@ int process_arguments(int argc, char **argv) {
183 if (argc < 2) 178 if (argc < 2)
184 usage("\n"); 179 usage("\n");
185 180
186 for (c = 1; c < argc; c++) { 181 for (int i = 1; i < argc; i++) {
187 if (strcmp("-to", argv[c]) == 0) 182 if (strcmp("-to", argv[i]) == 0)
188 strcpy(argv[c], "-t"); 183 strcpy(argv[i], "-t");
189 else if (strcmp("-wd", argv[c]) == 0) 184 else if (strcmp("-wd", argv[i]) == 0)
190 strcpy(argv[c], "-w"); 185 strcpy(argv[i], "-w");
191 else if (strcmp("-cd", argv[c]) == 0) 186 else if (strcmp("-cd", argv[i]) == 0)
192 strcpy(argv[c], "-c"); 187 strcpy(argv[i], "-c");
193 else if (strcmp("-wt", argv[c]) == 0) 188 else if (strcmp("-wt", argv[i]) == 0)
194 strcpy(argv[c], "-W"); 189 strcpy(argv[i], "-W");
195 else if (strcmp("-ct", argv[c]) == 0) 190 else if (strcmp("-ct", argv[i]) == 0)
196 strcpy(argv[c], "-C"); 191 strcpy(argv[i], "-C");
197 } 192 }
198 193
194 int option_char;
199 while (true) { 195 while (true) {
200 c = getopt_long(argc, argv, "hVH:w:c:W:C:p:t:u", longopts, &option); 196 int option = 0;
197 option_char = getopt_long(argc, argv, "hVH:w:c:W:C:p:t:u", longopts, &option);
201 198
202 if (c == -1 || c == EOF) 199 if (option_char == -1 || option_char == EOF)
203 break; 200 break;
204 201
205 switch (c) { 202 switch (option_char) {
206 case '?': /* print short usage statement if args not parsable */ 203 case '?': /* print short usage statement if args not parsable */
207 usage5(); 204 usage5();
208 case 'h': /* help */ 205 case 'h': /* help */
@@ -277,12 +274,12 @@ int process_arguments(int argc, char **argv) {
277 } 274 }
278 } 275 }
279 276
280 c = optind; 277 option_char = optind;
281 if (server_address == NULL) { 278 if (server_address == NULL) {
282 if (argc > c) { 279 if (argc > option_char) {
283 if (!is_host(argv[c])) 280 if (!is_host(argv[option_char]))
284 usage2(_("Invalid hostname/address"), optarg); 281 usage2(_("Invalid hostname/address"), optarg);
285 server_address = argv[c]; 282 server_address = argv[option_char];
286 } else { 283 } else {
287 usage4(_("Hostname was not supplied")); 284 usage4(_("Hostname was not supplied"));
288 } 285 }