summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_ntp.c64
1 files changed, 26 insertions, 38 deletions
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c
index abd254c..6c7c1e7 100644
--- a/plugins/check_ntp.c
+++ b/plugins/check_ntp.c
@@ -47,13 +47,16 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
47 47
48static char *server_address=NULL; 48static char *server_address=NULL;
49static int verbose=0; 49static int verbose=0;
50static double owarn=60; 50static int stratum=-1;
51static double ocrit=120; 51static char *owarn="60";
52static char *ocrit="120";
52static short do_jitter=0; 53static short do_jitter=0;
53static double jwarn=5000; 54static char *jwarn="5000";
54static double jcrit=10000; 55static char *jcrit="10000";
55 56
56int process_arguments (int, char **); 57int process_arguments (int, char **);
58thresholds *offset_thresholds = NULL;
59thresholds *jitter_thresholds = NULL;
57void print_help (void); 60void print_help (void);
58void print_usage (void); 61void print_usage (void);
59 62
@@ -686,18 +689,18 @@ int process_arguments(int argc, char **argv){
686 verbose++; 689 verbose++;
687 break; 690 break;
688 case 'w': 691 case 'w':
689 owarn = atof(optarg); 692 owarn = optarg;
690 break; 693 break;
691 case 'c': 694 case 'c':
692 ocrit = atof(optarg); 695 ocrit = optarg;
693 break; 696 break;
694 case 'j': 697 case 'j':
695 do_jitter=1; 698 do_jitter=1;
696 jwarn = atof(optarg); 699 jwarn = optarg;
697 break; 700 break;
698 case 'k': 701 case 'k':
699 do_jitter=1; 702 do_jitter=1;
700 jcrit = atof(optarg); 703 jcrit = optarg;
701 break; 704 break;
702 case 'H': 705 case 'H':
703 if(is_host(optarg) == FALSE) 706 if(is_host(optarg) == FALSE)
@@ -724,14 +727,6 @@ int process_arguments(int argc, char **argv){
724 } 727 }
725 } 728 }
726 729
727 if (ocrit < owarn){
728 usage4(_("Critical offset should be larger than warning offset"));
729 }
730
731 if (jcrit < jwarn){
732 usage4(_("Critical jitter should be larger than warning jitter"));
733 }
734
735 if(server_address == NULL){ 730 if(server_address == NULL){
736 usage4(_("Hostname was not supplied")); 731 usage4(_("Hostname was not supplied"));
737 } 732 }
@@ -742,16 +737,16 @@ int process_arguments(int argc, char **argv){
742char *perfd_offset (double offset) 737char *perfd_offset (double offset)
743{ 738{
744 return fperfdata ("offset", offset, "s", 739 return fperfdata ("offset", offset, "s",
745 TRUE, owarn, 740 TRUE, offset_thresholds->warning->end,
746 TRUE, ocrit, 741 TRUE, offset_thresholds->critical->end,
747 FALSE, 0, FALSE, 0); 742 FALSE, 0, FALSE, 0);
748} 743}
749 744
750char *perfd_jitter (double jitter) 745char *perfd_jitter (double jitter)
751{ 746{
752 return fperfdata ("jitter", jitter, "s", 747 return fperfdata ("jitter", jitter, "s",
753 do_jitter, jwarn, 748 do_jitter, jitter_thresholds->warning->end,
754 do_jitter, jcrit, 749 do_jitter, jitter_thresholds->critical->end,
755 TRUE, 0, FALSE, 0); 750 TRUE, 0, FALSE, 0);
756} 751}
757 752
@@ -760,11 +755,14 @@ int main(int argc, char *argv[]){
760 double offset=0, jitter=0; 755 double offset=0, jitter=0;
761 char *result_line, *perfdata_line; 756 char *result_line, *perfdata_line;
762 757
763 result=offset_result=jitter_result=STATE_UNKNOWN; 758 result = offset_result = jitter_result= STATE_UNKNOWN;
764 759
765 if (process_arguments (argc, argv) == ERROR) 760 if (process_arguments (argc, argv) == ERROR)
766 usage4 (_("Could not parse arguments")); 761 usage4 (_("Could not parse arguments"));
767 762
763 set_thresholds(&offset_thresholds, owarn, ocrit);
764 set_thresholds(&jitter_thresholds, jwarn, jcrit);
765
768 /* initialize alarm signal handling */ 766 /* initialize alarm signal handling */
769 signal (SIGALRM, socket_timeout_alarm_handler); 767 signal (SIGALRM, socket_timeout_alarm_handler);
770 768
@@ -772,14 +770,8 @@ int main(int argc, char *argv[]){
772 alarm (socket_timeout); 770 alarm (socket_timeout);
773 771
774 offset = offset_request(server_address, &offset_result); 772 offset = offset_request(server_address, &offset_result);
775 if(fabs(offset) > ocrit){ 773 result = get_status(fabs(offset), offset_thresholds);
776 result = STATE_CRITICAL; 774 result = max_state(result, offset_result);
777 } else if(fabs(offset) > owarn) {
778 result = STATE_WARNING;
779 } else {
780 result = STATE_OK;
781 }
782 result=max_state(result, offset_result);
783 775
784 /* If not told to check the jitter, we don't even send packets. 776 /* If not told to check the jitter, we don't even send packets.
785 * jitter is checked using NTP control packets, which not all 777 * jitter is checked using NTP control packets, which not all
@@ -788,17 +780,13 @@ int main(int argc, char *argv[]){
788 */ 780 */
789 if(do_jitter){ 781 if(do_jitter){
790 jitter=jitter_request(server_address, &jitter_result); 782 jitter=jitter_request(server_address, &jitter_result);
791 if(jitter > jcrit){ 783 result = max_state(result, get_status(jitter, jitter_thresholds));
792 result = max_state(result, STATE_CRITICAL); 784 /* -1 indicates that we couldn't calculate the jitter
793 } else if(jitter > jwarn) { 785 * Only overrides STATE_OK from the offset */
794 result = max_state(result, STATE_WARNING); 786 if(jitter == -1.0 && result == STATE_OK)
795 } else if(jitter == -1.0 && result == STATE_OK){
796 /* -1 indicates that we couldn't calculate the jitter
797 * Only overrides STATE_OK from the offset */
798 result = STATE_UNKNOWN; 787 result = STATE_UNKNOWN;
799 }
800 } 788 }
801 result=max_state(result, jitter_result); 789 result = max_state(result, jitter_result);
802 790
803 switch (result) { 791 switch (result) {
804 case STATE_CRITICAL : 792 case STATE_CRITICAL :