diff options
| author | Subhendu Ghosh <sghosh@users.sourceforge.net> | 2002-11-11 19:29:19 +0000 |
|---|---|---|
| committer | Subhendu Ghosh <sghosh@users.sourceforge.net> | 2002-11-11 19:29:19 +0000 |
| commit | 74cb2bc8c90429062eb424174b49de3ab8b9388e (patch) | |
| tree | 0d2441915dcb33df82f30a96d9ece1f6775ef336 /plugins | |
| parent | ab67f9e1d29460db3d99fe40e56c3a8f2665ad7f (diff) | |
| download | monitoring-plugins-74cb2bc8c90429062eb424174b49de3ab8b9388e.tar.gz | |
long opt for miblist, snmpv3 support (rosenauer)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@185 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_snmp.c | 119 |
1 files changed, 113 insertions, 6 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 7e574c5f..19306b58 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
| @@ -52,6 +52,18 @@ | |||
| 52 | Units label(s) for output data (e.g., 'sec.').\n\ | 52 | Units label(s) for output data (e.g., 'sec.').\n\ |
| 53 | -p, --port=STRING\n\ | 53 | -p, --port=STRING\n\ |
| 54 | UDP port number target is listening on. Default is \"%s\"\n\ | 54 | UDP port number target is listening on. Default is \"%s\"\n\ |
| 55 | -P, --protocol=[1|3]\n\ | ||
| 56 | SNMP protocol version\n\ | ||
| 57 | -L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]\n\ | ||
| 58 | SNMPv3 securityLevel\n\ | ||
| 59 | -U, --secname=USERNAME\n\ | ||
| 60 | SNMPv3 username\n\ | ||
| 61 | -a, --authproto=[MD5|SHA]\n\ | ||
| 62 | SNMPv3 auth proto\n\ | ||
| 63 | -A, --authpassword=PASSWORD\n\ | ||
| 64 | SNMPv3 authentication password\n\ | ||
| 65 | -X, --privpasswd=PASSWORD\n\ | ||
| 66 | SNMPv3 crypt passwd (DES)\n\ | ||
| 55 | -d, --delimiter=STRING\n\ | 67 | -d, --delimiter=STRING\n\ |
| 56 | Delimiter to use when parsing returned data. Default is \"%s\"\n\ | 68 | Delimiter to use when parsing returned data. Default is \"%s\"\n\ |
| 57 | Any data on the right hand side of the delimiter is considered\n\ | 69 | Any data on the right hand side of the delimiter is considered\n\ |
| @@ -100,6 +112,8 @@ This plugin gets system information on a remote server via snmp.\n" | |||
| 100 | #define DEFAULT_PORT "161" | 112 | #define DEFAULT_PORT "161" |
| 101 | #define DEFAULT_TIMEOUT 10 | 113 | #define DEFAULT_TIMEOUT 10 |
| 102 | #define DEFAULT_MIBLIST "ALL" | 114 | #define DEFAULT_MIBLIST "ALL" |
| 115 | #define DEFAULT_PROTOCOL "1" | ||
| 116 | #define DEFAULT_AUTH_PROTOCOL "MD5" | ||
| 103 | 117 | ||
| 104 | #include "common.h" | 118 | #include "common.h" |
| 105 | #include "utils.h" | 119 | #include "utils.h" |
| @@ -160,6 +174,13 @@ int errcode, excode; | |||
| 160 | 174 | ||
| 161 | char *server_address = NULL; | 175 | char *server_address = NULL; |
| 162 | char *community = NULL; | 176 | char *community = NULL; |
| 177 | char *authpriv = NULL; | ||
| 178 | char *proto = NULL; | ||
| 179 | char *seclevel = NULL; | ||
| 180 | char *secname = NULL; | ||
| 181 | char *authproto = NULL; | ||
| 182 | char *authpasswd = NULL; | ||
| 183 | char *privpasswd = NULL; | ||
| 163 | char *oid = ""; | 184 | char *oid = ""; |
| 164 | char *label = NULL; | 185 | char *label = NULL; |
| 165 | char *units = NULL; | 186 | char *units = NULL; |
| @@ -211,8 +232,8 @@ main (int argc, char **argv) | |||
| 211 | usage ("Incorrect arguments supplied\n"); | 232 | usage ("Incorrect arguments supplied\n"); |
| 212 | 233 | ||
| 213 | /* create the command line to execute */ | 234 | /* create the command line to execute */ |
| 214 | asprintf (&command_line, "%s -m %s -v 1 -c %s %s:%s %s", | 235 | asprintf (&command_line, "%s -m %s -v %s %s %s:%s %s", |
| 215 | PATH_TO_SNMPGET, miblist, community, server_address, port, oid); | 236 | PATH_TO_SNMPGET, miblist, proto, authpriv, server_address, port, oid); |
| 216 | if (verbose) | 237 | if (verbose) |
| 217 | printf ("%s\n", command_line); | 238 | printf ("%s\n", command_line); |
| 218 | 239 | ||
| @@ -404,6 +425,13 @@ process_arguments (int argc, char **argv) | |||
| 404 | {"label", required_argument, 0, 'l'}, | 425 | {"label", required_argument, 0, 'l'}, |
| 405 | {"units", required_argument, 0, 'u'}, | 426 | {"units", required_argument, 0, 'u'}, |
| 406 | {"port", required_argument, 0, 'p'}, | 427 | {"port", required_argument, 0, 'p'}, |
| 428 | {"miblist", required_argument, 0, 'm'}, | ||
| 429 | {"protocol", required_argument, 0, 'P'}, | ||
| 430 | {"seclevel", required_argument, 0, 'L'}, | ||
| 431 | {"secname", required_argument, 0, 'U'}, | ||
| 432 | {"authproto", required_argument, 0, 'a'}, | ||
| 433 | {"authpasswd", required_argument, 0, 'A'}, | ||
| 434 | {"privpasswd", required_argument, 0, 'X'}, | ||
| 407 | {0, 0, 0, 0} | 435 | {0, 0, 0, 0} |
| 408 | }; | 436 | }; |
| 409 | #endif | 437 | #endif |
| @@ -424,10 +452,10 @@ process_arguments (int argc, char **argv) | |||
| 424 | while (1) { | 452 | while (1) { |
| 425 | #ifdef HAVE_GETOPT_H | 453 | #ifdef HAVE_GETOPT_H |
| 426 | c = | 454 | c = |
| 427 | getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:", | 455 | getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:P:L:U:a:A:X:", |
| 428 | long_options, &option_index); | 456 | long_options, &option_index); |
| 429 | #else | 457 | #else |
| 430 | c = getopt (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:"); | 458 | c = getopt (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:P:L:U:a:A:X:"); |
| 431 | #endif | 459 | #endif |
| 432 | 460 | ||
| 433 | if (c == -1 || c == EOF) | 461 | if (c == -1 || c == EOF) |
| @@ -438,7 +466,7 @@ process_arguments (int argc, char **argv) | |||
| 438 | usage3 ("Unknown argument", optopt); | 466 | usage3 ("Unknown argument", optopt); |
| 439 | case 'h': /* help */ | 467 | case 'h': /* help */ |
| 440 | print_help (); | 468 | print_help (); |
| 441 | exit (STATE_OK); | 469 | exit (STATE_OK); |
| 442 | case 'V': /* version */ | 470 | case 'V': /* version */ |
| 443 | print_revision (PROGNAME, REVISION); | 471 | print_revision (PROGNAME, REVISION); |
| 444 | exit (STATE_OK); | 472 | exit (STATE_OK); |
| @@ -607,6 +635,24 @@ process_arguments (int argc, char **argv) | |||
| 607 | case 'm': /* List of MIBS */ | 635 | case 'm': /* List of MIBS */ |
| 608 | miblist = strscpy(miblist, optarg); | 636 | miblist = strscpy(miblist, optarg); |
| 609 | break; | 637 | break; |
| 638 | case 'P': /* SNMP protocol version */ | ||
| 639 | proto = strscpy(proto, optarg); | ||
| 640 | break; | ||
| 641 | case 'L': /* security level */ | ||
| 642 | seclevel = strscpy(seclevel,optarg); | ||
| 643 | break; | ||
| 644 | case 'U': /* security username */ | ||
| 645 | secname = strscpy(secname, optarg); | ||
| 646 | break; | ||
| 647 | case 'a': /* auth protocol */ | ||
| 648 | authproto = strscpy(authproto, optarg); | ||
| 649 | break; | ||
| 650 | case 'A': /* auth passwd */ | ||
| 651 | authpasswd = strscpy(authpasswd, optarg); | ||
| 652 | break; | ||
| 653 | case 'X': /* priv passwd */ | ||
| 654 | privpasswd = strscpy(privpasswd, optarg); | ||
| 655 | break; | ||
| 610 | 656 | ||
| 611 | } | 657 | } |
| 612 | } | 658 | } |
| @@ -659,9 +705,70 @@ validate_arguments () | |||
| 659 | if (units == NULL) | 705 | if (units == NULL) |
| 660 | asprintf (&units, ""); | 706 | asprintf (&units, ""); |
| 661 | 707 | ||
| 708 | if ( strcmp(seclevel, "noAuthNoPriv") && strcmp(seclevel, "authNoPriv") && strcmp(seclevel, "authPriv") ) { | ||
| 709 | if (seclevel == NULL) | ||
| 710 | asprintf (&seclevel, "noAuthNoPriv"); | ||
| 711 | else { | ||
| 712 | printf ("Invalid seclevel: %s! \n", seclevel); | ||
| 713 | print_usage (); | ||
| 714 | exit (STATE_UNKNOWN); | ||
| 715 | } | ||
| 716 | } | ||
| 717 | |||
| 718 | |||
| 719 | if ( strcmp (authproto, "SHA") && strcmp(authproto, "MD5") ) { | ||
| 720 | if (authproto == NULL ) | ||
| 721 | asprintf(&authproto, DEFAULT_AUTH_PROTOCOL); | ||
| 722 | else{ | ||
| 723 | printf ("Invalid authproto: %s! \n", authproto); | ||
| 724 | print_usage (); | ||
| 725 | exit (STATE_UNKNOWN); | ||
| 726 | } | ||
| 727 | } | ||
| 728 | |||
| 729 | |||
| 730 | |||
| 731 | if (proto == NULL || !strcmp(proto,DEFAULT_PROTOCOL) ) { /* default protocol version */ | ||
| 732 | asprintf(&proto, DEFAULT_PROTOCOL); | ||
| 733 | asprintf(&authpriv, "%s%s", "-c ", community); | ||
| 734 | } | ||
| 735 | else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */ | ||
| 736 | asprintf(&proto, "%s", "3"); | ||
| 737 | |||
| 738 | if ( (strcmp(seclevel, "noAuthNoPriv") == 0) || seclevel == NULL ) { | ||
| 739 | authpriv = ssprintf(authpriv, "%s", "-l noAuthNoPriv" ); | ||
| 740 | } | ||
| 741 | else if ( strcmp(seclevel, "authNoPriv") == 0 ) { | ||
| 742 | if ( secname == NULL || authpasswd == NULL) { | ||
| 743 | printf ("Missing secname (%s) or authpassword (%s) ! \n",secname, authpasswd ); | ||
| 744 | print_usage (); | ||
| 745 | exit (STATE_UNKNOWN); | ||
| 746 | } | ||
| 747 | authpriv = ssprintf(authpriv, "-l authNoPriv -a %s -u %s -A %s ", authproto, secname, authpasswd); | ||
| 748 | } | ||
| 749 | else if ( strcmp(seclevel, "authPriv") == 0 ) { | ||
| 750 | if ( secname == NULL || authpasswd == NULL || privpasswd == NULL ) { | ||
| 751 | printf ("Missing secname (%s), authpassword (%s), or privpasswd (%s)! \n",secname, authpasswd,privpasswd ); | ||
| 752 | print_usage (); | ||
| 753 | exit (STATE_UNKNOWN); | ||
| 754 | } | ||
| 755 | authpriv = ssprintf(authpriv, "-l authPriv -a %s -u %s -A %s -X %s ", authproto, secname, authpasswd, privpasswd); | ||
| 756 | } | ||
| 757 | |||
| 758 | |||
| 759 | } | ||
| 760 | else { | ||
| 761 | printf ("Invalid SNMP version: %s\n", proto); | ||
| 762 | print_usage (); | ||
| 763 | exit (STATE_UNKNOWN); | ||
| 764 | } | ||
| 765 | |||
| 766 | |||
| 767 | |||
| 768 | |||
| 662 | return OK; | 769 | return OK; |
| 663 | } | 770 | } |
| 664 | 771 | ||
| 665 | 772 | ||
| 666 | 773 | ||
| 667 | void | 774 | void |
