summaryrefslogtreecommitdiffstats
path: root/plugins/check_nt.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_nt.c')
-rw-r--r--plugins/check_nt.c134
1 files changed, 78 insertions, 56 deletions
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index 1305a333..9652fa6b 100644
--- a/plugins/check_nt.c
+++ b/plugins/check_nt.c
@@ -70,13 +70,11 @@ void preparelist(char *string);
70 70
71int main(int argc, char **argv){ 71int main(int argc, char **argv){
72 int result; 72 int result;
73 int return_code; 73 int return_code = STATE_UNKNOWN;
74 char *send_buffer=NULL; 74 char *send_buffer=NULL;
75 char recv_buffer[MAX_INPUT_BUFFER]; 75 char recv_buffer[MAX_INPUT_BUFFER];
76 char *output_message=NULL; 76 char *output_message=NULL;
77 char *temp_buffer=NULL;
78 char *temp_string=NULL; 77 char *temp_string=NULL;
79 char *sep_string=NULL;
80 char *description=NULL; 78 char *description=NULL;
81 79
82 double total_disk_space=0; 80 double total_disk_space=0;
@@ -84,18 +82,15 @@ int main(int argc, char **argv){
84 double percent_used_space=0; 82 double percent_used_space=0;
85 double mem_commitLimit=0; 83 double mem_commitLimit=0;
86 double mem_commitByte=0; 84 double mem_commitByte=0;
87 unsigned long current_connections=0;
88 unsigned long utilization; 85 unsigned long utilization;
89 unsigned long uptime; 86 unsigned long uptime;
90 unsigned long cache_hits;
91 unsigned long cache_buffers;
92 unsigned long lru_time;
93 unsigned long age_in_minutes; 87 unsigned long age_in_minutes;
94 double counter_value; 88 double counter_value;
95 int offset=0; 89 int offset=0;
96 int updays=0; 90 int updays=0;
97 int uphours=0; 91 int uphours=0;
98 int upminutes=0; 92 int upminutes=0;
93
99 asprintf(&req_password,"None"); 94 asprintf(&req_password,"None");
100 95
101 if(process_arguments(argc,argv)==ERROR) 96 if(process_arguments(argc,argv)==ERROR)
@@ -108,14 +103,16 @@ int main(int argc, char **argv){
108 alarm(socket_timeout); 103 alarm(socket_timeout);
109 104
110 if (vars_to_check==CHECK_CLIENTVERSION) { 105 if (vars_to_check==CHECK_CLIENTVERSION) {
111 106
112 asprintf(&send_buffer,strcat(req_password,"&1")); 107 asprintf(&send_buffer,strcat(req_password,"&1"));
113 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 108 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
114 if(result!=STATE_OK) 109 if(result!=STATE_OK)
115 return result; 110 return result;
116 asprintf(&output_message,recv_buffer); 111 asprintf(&output_message,recv_buffer);
117 return_code=STATE_OK; 112 return_code=STATE_OK;
113
118 } 114 }
115
119 else if(vars_to_check==CHECK_CPULOAD){ 116 else if(vars_to_check==CHECK_CPULOAD){
120 117
121 if (check_value_list==TRUE) { 118 if (check_value_list==TRUE) {
@@ -123,9 +120,12 @@ int main(int argc, char **argv){
123 /* -l parameters is present with only integers */ 120 /* -l parameters is present with only integers */
124 return_code=STATE_OK; 121 return_code=STATE_OK;
125 asprintf(&temp_string,"CPU Load"); 122 asprintf(&temp_string,"CPU Load");
126 while (lvalue_list[0+offset]>0 && lvalue_list[0+offset]<=17280 && 123 while (lvalue_list[0+offset]>(unsigned long)0 &&
127 lvalue_list[1+offset]>=0 && lvalue_list[1+offset]<=100 && 124 lvalue_list[0+offset]<=(unsigned long)17280 &&
128 lvalue_list[2+offset]>=0 && lvalue_list[2+offset]<=100) { 125 lvalue_list[1+offset]>=(unsigned long)0 &&
126 lvalue_list[1+offset]<=(unsigned long)100 &&
127 lvalue_list[2+offset]>=(unsigned long)0 &&
128 lvalue_list[2+offset]<=(unsigned long)100) {
129 /* loop until one of the parameters is wrong or not present */ 129 /* loop until one of the parameters is wrong or not present */
130 130
131 /* Send request and retrieve data */ 131 /* Send request and retrieve data */
@@ -514,51 +514,73 @@ void print_usage(void)
514void print_help(void) 514void print_help(void)
515{ 515{
516 print_revision(progname,"$Revision$"); 516 print_revision(progname,"$Revision$");
517 printf 517 printf ("\
518 ("Copyright (c) 2000 Yves Rubin (rubiyz@yahoo.com)\n\n" 518Copyright (c) 2000 Yves Rubin (rubiyz@yahoo.com)\n\n\
519 "This plugin attempts to contact the NSClient service running on a Windows NT/2000/XP server to\n" 519This plugin collects data from the NSClient service running on a\n\
520 "gather the requested system information.\n\n"); 520Windows NT/2000/XP server.\n\n");
521 print_usage(); 521 print_usage();
522 printf 522 printf ("\nOptions:\n\
523 ("\nOptions:\n" 523-H, --hostname=HOST\n\
524 "-H, --hostname=HOST\n" 524 Name of the host to check\n\
525 " Name of the host to check\n" 525-p, --port=INTEGER\n\
526 "-p, --port=INTEGER\n" 526 Optional port number (default: %d)\n\
527 " Optional port number (default: %d)\n" 527-s <password>\n\
528 "-s <password>\n" 528 Password needed for the request\n\
529 " Password needed for the request\n" 529-w, --warning=INTEGER\n\
530 "-v, --variable=STRING\n" 530 Threshold which will result in a warning status\n\
531 " Variable to check. Valid variables are:\n" 531-c, --critical=INTEGER\n\
532 " CLIENTVERSION = Get the NSClient version\n" 532 Threshold which will result in a critical status\n\
533 " CPULOAD = Average CPU load on last x minutes. Request a -l parameter with the following syntax:\n" 533-t, --timeout=INTEGER\n\
534 " -l <minutes range>,<warning threshold>,<critical threshold>. <minute range> should be less than 24*60.\n" 534 Seconds before connection attempt times out (default: %d)\n\
535 " Thresholds are percentage and up to 10 requests can be done in one shot. ie: -l 60,90,95,120,90,95\n" 535-h, --help\n\
536 " UPTIME = Get the uptime of the machine. No specific parameters. No warning or critical threshold\n" 536 Print this help screen\n\
537 " USEDDISKSPACE = Size and percentage of disk use. Request a -l parameter containing the drive letter only.\n" 537-V, --version\n\
538 " Warning and critical thresholds can be specified with -w and -c.\n" 538 Print version information\n",
539 " MEMUSE = Memory use. Warning and critical thresholds can be specified with -w and -c.\n" 539 PORT, DEFAULT_SOCKET_TIMEOUT);
540 " SERVICESTATE = Check the state of one or several services. Request a -l parameters with the following syntax:\n" 540 printf ("\
541 " -l <service1>,<service2>,<service3>,... You can specify -d SHOWALL in case you want to see working services\n" 541-v, --variable=STRING\n\
542 " in the returned string.\n" 542 Variable to check. Valid variables are:\n");
543 " PROCSTATE = Check if one or several process are running. Same syntax as SERVICESTATE.\n" 543 printf ("\
544 " COUNTER = Check any performance counter of Windows NT/2000. Request a -l parameters with the following syntax:\n" 544 CLIENTVERSION = Get the NSClient version\n");
545 " -l \"\\\\<performance object>\\\\counter\",\"<description>\" The <description> parameter is optional and \n" 545 printf ("\
546 " is given to a printf output command which require a float parameters. Some examples:\n" 546 CPULOAD = Average CPU load on last x minutes.\n\
547 " \"Paging file usage is %%.2f %%%%\" or \"%%.f %%%% paging file used.\"\n" 547 Request a -l parameter with the following syntax:\n\
548 " -w, --warning=INTEGER\n" 548 -l <minutes range>,<warning threshold>,<critical threshold>.\n\
549 " Threshold which will result in a warning status\n" 549 <minute range> should be less than 24*60.\n\
550 " -c, --critical=INTEGER\n" 550 Thresholds are percentage and up to 10 requests can be done in one shot.\n\
551 " Threshold which will result in a critical status\n" 551 ie: -l 60,90,95,120,90,95\n");
552 " -t, --timeout=INTEGER\n" 552 printf ("\
553 " Seconds before connection attempt times out (default: %d)\n" 553 UPTIME = Get the uptime of the machine.\n\
554 "-h, --help\n" 554 No specific parameters. No warning or critical threshold\n");
555 " Print this help screen\n" 555 printf ("\
556 "-V, --version\n" 556 USEDDISKSPACE = Size and percentage of disk use.\n\
557 " Print version information\n\n" 557 Request a -l parameter containing the drive letter only.\n\
558 "Notes:\n" 558 Warning and critical thresholds can be specified with -w and -c.\n");
559 " - The NSClient service should be running on the server to get any information\n" 559 printf ("\
560 " (http://nsclient.ready2run.nl).\n" 560 MEMUSE = Memory use.\n\
561 " - Critical thresholds should be lower than warning thresholds\n", PORT, DEFAULT_SOCKET_TIMEOUT); 561 Warning and critical thresholds can be specified with -w and -c.\n");
562 printf ("\
563 SERVICESTATE = Check the state of one or several services.\n\
564 Request a -l parameters with the following syntax:\n\
565 -l <service1>,<service2>,<service3>,...\n\
566 You can specify -d SHOWALL in case you want to see working services\n\
567 in the returned string.\n");
568 printf ("\
569 PROCSTATE = Check if one or several process are running.\n\
570 Same syntax as SERVICESTATE.\n");
571 printf ("\
572 COUNTER = Check any performance counter of Windows NT/2000.\n\
573 Request a -l parameters with the following syntax:\n\
574 -l \"\\\\<performance object>\\\\counter\",\"<description>\n\
575 The <description> parameter is optional and \n\
576 is given to a printf output command which require a float parameters.\n\
577 Some examples:\n\
578 \"Paging file usage is %%.2f %%%%\"\n\
579 \"%%.f %%%% paging file used.\"\n");
580 printf ("Notes:\n\
581 - The NSClient service should be running on the server to get any information\n\
582 (http://nsclient.ready2run.nl).\n\
583 - Critical thresholds should be lower than warning thresholds\n");
562} 584}
563 585
564int strtolarray(unsigned long *array, char *string, char *delim) { 586int strtolarray(unsigned long *array, char *string, char *delim) {
@@ -584,7 +606,7 @@ void preparelist(char *string) {
584 /* Replace all , with & which is the delimiter for the request */ 606 /* Replace all , with & which is the delimiter for the request */
585 int i; 607 int i;
586 608
587 for (i = 0; i < strlen(string); i++) 609 for (i = 0; (size_t)i < strlen(string); i++)
588 if (string[i] == ',') { 610 if (string[i] == ',') {
589 string[i]='&'; 611 string[i]='&';
590 } 612 }