summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_hpjd.c112
-rw-r--r--plugins/check_http.c8
-rw-r--r--plugins/check_nt.c134
3 files changed, 117 insertions, 137 deletions
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c
index 9d8fae2..5638465 100644
--- a/plugins/check_hpjd.c
+++ b/plugins/check_hpjd.c
@@ -1,50 +1,5 @@
1/****************************************************************************** 1/******************************************************************************
2* 2*
3* CHECK_HPJD.C
4*
5* Program: HP printer plugin for Nagios
6* License: GPL
7* Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
8*
9* Last Modified: $Date$
10*
11* Command line: CHECK_HPJD <ip_address> [community]
12*
13* Description:
14*
15* This plugin will attempt to check the status of an HP printer. The
16* printer must have a JetDirect card installed and TCP/IP protocol
17* stack enabled. This plugin has only been tested on a few printers
18* and may not work well on all models of JetDirect cards. Multiple
19* port JetDirect devices must have an IP address assigned to each
20* port in order to be monitored.
21*
22* Dependencies:
23*
24* This plugin used the 'snmpget' command included with the UCD-SNMP
25* package. If you don't have the package installed you will need to
26* download it from http://ucd-snmp.ucdavis.edu before you can use
27* this plugin.
28*
29* Return Values:
30*
31* UNKNOWN = The plugin could not read/process the output from the printer
32* OK = Printer looks normal
33* WARNING = Low toner, paper jam, intervention required, paper out, etc.
34* CRITICAL = The printer could not be reached (it's probably turned off)
35*
36* Acknowledgements:
37*
38* The idea for the plugin (as well as some code) were taken from Jim
39* Trocki's pinter alert script in his "mon" utility, found at
40* http://www.kernel.org/software/mon
41*
42* Notes:
43* 'JetDirect' is copyrighted by Hewlett-Packard.
44* HP, please don't sue me... :-)
45*
46* License Information:
47*
48* This program is free software; you can redistribute it and/or modify 3* This program is free software; you can redistribute it and/or modify
49* it under the terms of the GNU General Public License as published by 4* it under the terms of the GNU General Public License as published by
50* the Free Software Foundation; either version 2 of the License, or 5* the Free Software Foundation; either version 2 of the License, or
@@ -66,8 +21,26 @@
66#include "utils.h" 21#include "utils.h"
67 22
68const char *progname = "check_hpjd"; 23const char *progname = "check_hpjd";
69#define REVISION "$Revision$" 24const char *revision = "$Revision$";
70#define COPYRIGHT "2000-2002" 25const char *authors = "Nagios Plugin Development Team";
26const char *email = "nagiosplug-devel@lists.sourceforge.net";
27const char *copyright = "2000-2003";
28
29const char *summary = "\
30This plugin tests the STATUS of an HP printer with a JetDirect card.\n\
31Net-snmp must be installed on the computer running the plugin.\n\n";
32
33const char *option_summary = "-H host [-C community]\n";
34
35const char *options = "\
36 -H, --hostname=STRING or IPADDRESS\n\
37 Check server on the indicated host\n\
38 -C, --community=STRING\n\
39 The SNMP community name (default=%s)\n\
40 -h, --help\n\
41 Print detailed help screen\n\
42 -V, --version\n\
43 Print version information\n\n";
71 44
72#define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1" 45#define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1"
73#define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2" 46#define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2"
@@ -425,7 +398,7 @@ process_arguments (int argc, char **argv)
425 community = strscpy (community, optarg); 398 community = strscpy (community, optarg);
426 break; 399 break;
427 case 'V': /* version */ 400 case 'V': /* version */
428 print_revision (progname, REVISION); 401 print_revision (progname, revision);
429 exit (STATE_OK); 402 exit (STATE_OK);
430 case 'h': /* help */ 403 case 'h': /* help */
431 print_help (); 404 print_help ();
@@ -469,60 +442,43 @@ validate_arguments (void)
469void 442void
470print_help (void) 443print_help (void)
471{ 444{
472 print_revision (progname, REVISION); 445 print_revision (progname, revision);
473 printf 446 printf ("Copyright (c) %s %s\n\t<%s>\n\n", copyright, authors, email);
474 ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" 447 printf (summary);
475 "This plugin tests the STATUS of an HP printer with a JetDirect card.\n"
476 "Net-snmp must be installed on the computer running the plugin.\n\n");
477 print_usage (); 448 print_usage ();
478 printf 449 printf ("\nOptions:\n");
479 ("\nOptions:\n" 450 printf (options, DEFAULT_COMMUNITY);
480 " -H, --hostname=STRING or IPADDRESS\n"
481 " Check server on the indicated host\n"
482 " -C, --community=STRING\n"
483 " The SNMP community name (default=%s)\n"
484 " -h, --help\n"
485 " Print detailed help screen\n"
486 " -V, --version\n" " Print version information\n\n",DEFAULT_COMMUNITY);
487 support (); 451 support ();
488} 452}
489 453
490
491
492
493
494void 454void
495print_usage (void) 455print_usage (void)
496{ 456{
497 printf 457 printf ("\
498 ("Usage: %s -H host [-C community]\n" 458Usage:\n\
499 " %s --help\n" 459 %s %s\n\
500 " %s --version\n", progname, progname, progname); 460 %s (-h | --help) for detailed help\n\
461 %s (-V | --version) for version information\n",
462 progname, option_summary, progname, progname);
501} 463}
502 464
503 465
504/* 466/*
505 if(argc<2||argc>3){ 467 if(argc<2||argc>3){
506 printf("Incorrect number of arguments supplied\n"); 468 printf("Incorrect number of arguments supplied\n");
507 printf("\n");
508 print_revision(argv[0],"$Revision$"); 469 print_revision(argv[0],"$Revision$");
509 printf("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n"); 470 printf("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n");
510 printf("License: GPL\n"); 471 printf("License: GPL\n");
511 printf("\n");
512 printf("Usage: %s <ip_address> [community]\n",argv[0]); 472 printf("Usage: %s <ip_address> [community]\n",argv[0]);
513 printf("\n");
514 printf("Note:\n"); 473 printf("Note:\n");
515 printf(" <ip_address> = The IP address of the JetDirect card\n"); 474 printf(" <ip_address> = The IP address of the JetDirect card\n");
516 printf(" [community] = An optional community string used for SNMP communication\n"); 475 printf(" [community] = An optional community string used for SNMP communication\n");
517 printf(" with the JetDirect card. The default is 'public'.\n"); 476 printf(" with the JetDirect card. The default is 'public'.\n");
518 printf("\n");
519 return STATE_UNKNOWN; 477 return STATE_UNKNOWN;
520 } 478 }
521 479 // get the IP address of the JetDirect device
522 /* get the IP address of the JetDirect device */
523 strcpy(address,argv[1]); 480 strcpy(address,argv[1]);
524 481 // get the community name to use for SNMP communication
525 /* get the community name to use for SNMP communication */
526 if(argc>=3) 482 if(argc>=3)
527 strcpy(community,argv[2]); 483 strcpy(community,argv[2]);
528 else 484 else
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 31d8646..7678084 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -1062,8 +1062,10 @@ print_help (void)
1062void 1062void
1063print_usage (void) 1063print_usage (void)
1064{ 1064{
1065 printf ("Usage:\n" " %s %s\n" 1065 printf ("\
1066 " %s (-h | --help) for detailed help\n" 1066Usage:\n\
1067 " %s (-V | --version) for version information\n", 1067 %s %s\n\
1068 %s (-h | --help) for detailed help\n\
1069 %s (-V | --version) for version information\n",
1068 progname, OPTIONS, progname, progname); 1070 progname, OPTIONS, progname, progname);
1069} 1071}
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index 1305a33..9652fa6 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 }