Changeset a5df09d25bd13bf1f726673e2b03f59b6066bf59
- Timestamp:
- 02/02/12 22:32:36
(1 year ago)
- Author:
- Theo Schlossnagle <jesus@omniti.com>
- git-committer:
- Theo Schlossnagle <jesus@omniti.com> 1328221956 -0500
- git-parent:
[a64139dcd7cce8a609a80ee6827795c4ee240da5]
- git-author:
- Theo Schlossnagle <jesus@omniti.com> 1328221956 -0500
- Message:
support v1 of SNMP. Perhaps support v3 (untested)
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r7ae62b9 |
ra5df09d |
|
| 75 | 75 | </variablelist> |
|---|
| 76 | 76 | <para>The UDP port to which SNMP queries will be sent.</para> |
|---|
| | 77 | </listitem> |
|---|
| | 78 | </varlistentry> |
|---|
| | 79 | </variablelist> |
|---|
| | 80 | <variablelist> |
|---|
| | 81 | <varlistentry> |
|---|
| | 82 | <term>version</term> |
|---|
| | 83 | <listitem> |
|---|
| | 84 | <variablelist> |
|---|
| | 85 | <varlistentry> |
|---|
| | 86 | <term>required</term> |
|---|
| | 87 | <listitem> |
|---|
| | 88 | <para>optional</para> |
|---|
| | 89 | </listitem> |
|---|
| | 90 | </varlistentry> |
|---|
| | 91 | <varlistentry> |
|---|
| | 92 | <term>default</term> |
|---|
| | 93 | <listitem> |
|---|
| | 94 | <para>2c</para> |
|---|
| | 95 | </listitem> |
|---|
| | 96 | </varlistentry> |
|---|
| | 97 | <varlistentry> |
|---|
| | 98 | <term>allowed</term> |
|---|
| | 99 | <listitem> |
|---|
| | 100 | <para>(1|2c|3)</para> |
|---|
| | 101 | </listitem> |
|---|
| | 102 | </varlistentry> |
|---|
| | 103 | </variablelist> |
|---|
| | 104 | <para>The SNMP version used for queries.</para> |
|---|
| 77 | 105 | </listitem> |
|---|
| 78 | 106 | </varlistentry> |
|---|
| r7ae62b9 |
ra5df09d |
|
| 124 | 124 | void *sess_handle; |
|---|
| 125 | 125 | noit_module_t *self; |
|---|
| | 126 | char *key; |
|---|
| 126 | 127 | char *target; |
|---|
| 127 | 128 | eventer_t timeoutevent; |
|---|
| … | … | |
| 153 | 154 | noit_check_t *check; |
|---|
| 154 | 155 | struct target_session *ts; |
|---|
| | 156 | int version; |
|---|
| 155 | 157 | }; |
|---|
| 156 | 158 | |
|---|
| … | … | |
| 178 | 180 | |
|---|
| 179 | 181 | struct target_session * |
|---|
| 180 | | _get_target_session(noit_module_t *self, char *target) { |
|---|
| | 182 | _get_target_session(noit_module_t *self, char *target, int version) { |
|---|
| | 183 | char key[128]; |
|---|
| 181 | 184 | void *vts; |
|---|
| 182 | 185 | struct target_session *ts; |
|---|
| 183 | 186 | snmp_mod_config_t *conf; |
|---|
| 184 | 187 | conf = noit_module_get_userdata(self); |
|---|
| | 188 | snprintf(key, sizeof(key), "%s:v%d", target, version); |
|---|
| 185 | 189 | if(!noit_hash_retrieve(&conf->target_sessions, |
|---|
| 186 | | target, strlen(target), &vts)) { |
|---|
| | 190 | key, strlen(key), &vts)) { |
|---|
| 187 | 191 | ts = calloc(1, sizeof(*ts)); |
|---|
| 188 | 192 | ts->self = self; |
|---|
| … | … | |
| 190 | 194 | ts->refcnt = 0; |
|---|
| 191 | 195 | ts->target = strdup(target); |
|---|
| | 196 | ts->key = strdup(key); |
|---|
| 192 | 197 | ts->in_table = 1; |
|---|
| 193 | 198 | noit_hash_store(&conf->target_sessions, |
|---|
| 194 | | ts->target, strlen(ts->target), ts); |
|---|
| | 199 | ts->key, strlen(ts->key), ts); |
|---|
| 195 | 200 | vts = ts; |
|---|
| 196 | 201 | } |
|---|
| … | … | |
| 818 | 823 | const char *community; |
|---|
| 819 | 824 | struct snmp_session sess; |
|---|
| | 825 | struct check_info *info = check->closure; |
|---|
| 820 | 826 | snmp_sess_init(&sess); |
|---|
| 821 | | sess.version = SNMP_VERSION_2c; |
|---|
| | 827 | sess.version = info->version; |
|---|
| 822 | 828 | sess.peername = ts->target; |
|---|
| 823 | 829 | if(!noit_hash_retr_str(check->config, "community", strlen("community"), |
|---|
| … | … | |
| 925 | 931 | struct check_info *info = check->closure; |
|---|
| 926 | 932 | int port = 161; |
|---|
| 927 | | const char *portstr; |
|---|
| | 933 | const char *portstr, *versstr; |
|---|
| 928 | 934 | char target_port[64]; |
|---|
| 929 | 935 | |
|---|
| | 936 | info->version = SNMP_VERSION_2c; |
|---|
| 930 | 937 | info->self = self; |
|---|
| 931 | 938 | info->check = check; |
|---|
| … | … | |
| 938 | 945 | port = atoi(portstr); |
|---|
| 939 | 946 | } |
|---|
| | 947 | if(noit_hash_retr_str(check->config, "version", strlen("version"), |
|---|
| | 948 | &versstr)) { |
|---|
| | 949 | /* We don't care about 2c or others... as they all default to 2c */ |
|---|
| | 950 | if(!strcmp(versstr, "1")) info->version = SNMP_VERSION_1; |
|---|
| | 951 | if(!strcmp(versstr, "3")) info->version = SNMP_VERSION_3; |
|---|
| | 952 | } |
|---|
| 940 | 953 | snprintf(target_port, sizeof(target_port), "%s:%d", check->target_ip, port); |
|---|
| 941 | | ts = _get_target_session(self, target_port); |
|---|
| | 954 | ts = _get_target_session(self, target_port, info->version); |
|---|
| 942 | 955 | gettimeofday(&check->last_fire_time, NULL); |
|---|
| 943 | 956 | if(!ts->refcnt) { |
|---|
| … | … | |
| 968 | 981 | req = snmp_pdu_create(SNMP_MSG_GET); |
|---|
| 969 | 982 | if(req) noit_snmp_fill_req(req, check); |
|---|
| | 983 | req->version = info->version; |
|---|
| 970 | 984 | /* Setup out snmp requests */ |
|---|
| 971 | 985 | if(ts->sess_handle && req && |
|---|
| … | … | |
| 1135 | 1149 | return -1; |
|---|
| 1136 | 1150 | } |
|---|
| 1137 | | ts = _get_target_session(self, "snmptrapd"); |
|---|
| | 1151 | ts = _get_target_session(self, "snmptrapd", SNMP_DEFAULT_VERSION); |
|---|
| 1138 | 1152 | snmp_sess_init(session); |
|---|
| 1139 | 1153 | session->peername = SNMP_DEFAULT_PEERNAME; |
|---|
| r7ae62b9 |
ra5df09d |
|
| 14 | 14 | default="161" |
|---|
| 15 | 15 | allowed="\d+">The UDP port to which SNMP queries will be sent.</parameter> |
|---|
| | 16 | <parameter name="version" |
|---|
| | 17 | required="optional" |
|---|
| | 18 | default="2c" |
|---|
| | 19 | allowed="(1|2c|3)">The SNMP version used for queries.</parameter> |
|---|
| 16 | 20 | <parameter name="oid_.+" |
|---|
| 17 | 21 | required="optional" |
|---|