diff options
Diffstat (limited to 'plugins/check_time.c')
| -rw-r--r-- | plugins/check_time.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/plugins/check_time.c b/plugins/check_time.c index debf59f3..99708ad3 100644 --- a/plugins/check_time.c +++ b/plugins/check_time.c | |||
| @@ -68,6 +68,7 @@ int main(int argc, char **argv) { | |||
| 68 | 68 | ||
| 69 | /* set socket timeout */ | 69 | /* set socket timeout */ |
| 70 | alarm(socket_timeout); | 70 | alarm(socket_timeout); |
| 71 | time_t start_time; | ||
| 71 | time(&start_time); | 72 | time(&start_time); |
| 72 | 73 | ||
| 73 | int socket; | 74 | int socket; |
| @@ -87,7 +88,8 @@ int main(int argc, char **argv) { | |||
| 87 | } else { | 88 | } else { |
| 88 | result = STATE_UNKNOWN; | 89 | result = STATE_UNKNOWN; |
| 89 | } | 90 | } |
| 90 | die(result, _("TIME UNKNOWN - could not connect to server %s, port %d\n"), config.server_address, config.server_port); | 91 | die(result, _("TIME UNKNOWN - could not connect to server %s, port %d\n"), |
| 92 | config.server_address, config.server_port); | ||
| 91 | } | 93 | } |
| 92 | 94 | ||
| 93 | if (config.use_udp) { | 95 | if (config.use_udp) { |
| @@ -99,7 +101,8 @@ int main(int argc, char **argv) { | |||
| 99 | } else { | 101 | } else { |
| 100 | result = STATE_UNKNOWN; | 102 | result = STATE_UNKNOWN; |
| 101 | } | 103 | } |
| 102 | die(result, _("TIME UNKNOWN - could not send UDP request to server %s, port %d\n"), config.server_address, config.server_port); | 104 | die(result, _("TIME UNKNOWN - could not send UDP request to server %s, port %d\n"), |
| 105 | config.server_address, config.server_port); | ||
| 103 | } | 106 | } |
| 104 | } | 107 | } |
| 105 | 108 | ||
| @@ -111,6 +114,7 @@ int main(int argc, char **argv) { | |||
| 111 | close(socket); | 114 | close(socket); |
| 112 | 115 | ||
| 113 | /* reset the alarm */ | 116 | /* reset the alarm */ |
| 117 | time_t end_time; | ||
| 114 | time(&end_time); | 118 | time(&end_time); |
| 115 | alarm(0); | 119 | alarm(0); |
| 116 | 120 | ||
| @@ -123,7 +127,8 @@ int main(int argc, char **argv) { | |||
| 123 | } else { | 127 | } else { |
| 124 | result = STATE_UNKNOWN; | 128 | result = STATE_UNKNOWN; |
| 125 | } | 129 | } |
| 126 | die(result, _("TIME UNKNOWN - no data received from server %s, port %d\n"), config.server_address, config.server_port); | 130 | die(result, _("TIME UNKNOWN - no data received from server %s, port %d\n"), |
| 131 | config.server_address, config.server_port); | ||
| 127 | } | 132 | } |
| 128 | 133 | ||
| 129 | result = STATE_OK; | 134 | result = STATE_OK; |
| @@ -137,7 +142,8 @@ int main(int argc, char **argv) { | |||
| 137 | 142 | ||
| 138 | if (result != STATE_OK) { | 143 | if (result != STATE_OK) { |
| 139 | die(result, _("TIME %s - %d second response time|%s\n"), state_text(result), (int)conntime, | 144 | die(result, _("TIME %s - %d second response time|%s\n"), state_text(result), (int)conntime, |
| 140 | perfdata("time", (long)conntime, "s", config.check_warning_time, (long)config.warning_time, config.check_critical_time, | 145 | perfdata("time", (long)conntime, "s", config.check_warning_time, |
| 146 | (long)config.warning_time, config.check_critical_time, | ||
| 141 | (long)config.critical_time, true, 0, false, 0)); | 147 | (long)config.critical_time, true, 0, false, 0)); |
| 142 | } | 148 | } |
| 143 | 149 | ||
| @@ -157,10 +163,11 @@ int main(int argc, char **argv) { | |||
| 157 | } | 163 | } |
| 158 | 164 | ||
| 159 | printf(_("TIME %s - %lu second time difference|%s %s\n"), state_text(result), diff_time, | 165 | printf(_("TIME %s - %lu second time difference|%s %s\n"), state_text(result), diff_time, |
| 160 | perfdata("time", (long)conntime, "s", config.check_warning_time, (long)config.warning_time, config.check_critical_time, | 166 | perfdata("time", (long)conntime, "s", config.check_warning_time, |
| 167 | (long)config.warning_time, config.check_critical_time, | ||
| 161 | (long)config.critical_time, true, 0, false, 0), | 168 | (long)config.critical_time, true, 0, false, 0), |
| 162 | perfdata("offset", diff_time, "s", config.check_warning_diff, config.warning_diff, config.check_critical_diff, | 169 | perfdata("offset", diff_time, "s", config.check_warning_diff, config.warning_diff, |
| 163 | config.critical_diff, true, 0, false, 0)); | 170 | config.check_critical_diff, config.critical_diff, true, 0, false, 0)); |
| 164 | return result; | 171 | return result; |
| 165 | } | 172 | } |
| 166 | 173 | ||
| @@ -230,7 +237,8 @@ check_time_config_wrapper process_arguments(int argc, char **argv) { | |||
| 230 | result.config.warning_diff = strtoul(optarg, NULL, 10); | 237 | result.config.warning_diff = strtoul(optarg, NULL, 10); |
| 231 | result.config.check_warning_diff = true; | 238 | result.config.check_warning_diff = true; |
| 232 | } else if (strspn(optarg, "0123456789:,") > 0) { | 239 | } else if (strspn(optarg, "0123456789:,") > 0) { |
| 233 | if (sscanf(optarg, "%lu%*[:,]%d", &result.config.warning_diff, &result.config.warning_time) == 2) { | 240 | if (sscanf(optarg, "%lu%*[:,]%d", &result.config.warning_diff, |
| 241 | &result.config.warning_time) == 2) { | ||
| 234 | result.config.check_warning_diff = true; | 242 | result.config.check_warning_diff = true; |
| 235 | result.config.check_warning_time = true; | 243 | result.config.check_warning_time = true; |
| 236 | } else { | 244 | } else { |
| @@ -245,7 +253,8 @@ check_time_config_wrapper process_arguments(int argc, char **argv) { | |||
| 245 | result.config.critical_diff = strtoul(optarg, NULL, 10); | 253 | result.config.critical_diff = strtoul(optarg, NULL, 10); |
| 246 | result.config.check_critical_diff = true; | 254 | result.config.check_critical_diff = true; |
| 247 | } else if (strspn(optarg, "0123456789:,") > 0) { | 255 | } else if (strspn(optarg, "0123456789:,") > 0) { |
| 248 | if (sscanf(optarg, "%lu%*[:,]%d", &result.config.critical_diff, &result.config.critical_time) == 2) { | 256 | if (sscanf(optarg, "%lu%*[:,]%d", &result.config.critical_diff, |
| 257 | &result.config.critical_time) == 2) { | ||
| 249 | result.config.check_critical_diff = true; | 258 | result.config.check_critical_diff = true; |
| 250 | result.config.check_critical_time = true; | 259 | result.config.check_critical_time = true; |
| 251 | } else { | 260 | } else { |
