Changeset 7fbea6436b3d271e41e913291bb1bd2f606358e3
- Timestamp:
- 12/21/10 22:39:59 (2 years ago)
- git-parent:
- Files:
-
- src/modules/snmp.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/modules/snmp.c
ra5e761d r7fbea64 129 129 int in_table; 130 130 int refcnt; 131 struct timeval last_open; 131 132 }; 132 133 … … 149 150 noit_module_t *self; 150 151 noit_check_t *check; 152 struct target_session *ts; 151 153 }; 152 154 … … 340 342 struct check_info *info = closure; 341 343 info->timedout = 1; 344 if(info->ts) { 345 info->ts->refcnt--; 346 noit_snmp_session_cleanse(info->ts); 347 info->ts = NULL; 348 } 342 349 remove_check(info); 343 350 /* Log our findings */ … … 739 746 current.available = NP_AVAILABLE; 740 747 748 /* Rate limit */ 749 if(((current.whence.tv_sec * 1000 + 750 current.whence.tv_usec / 1000) - 751 (check->last_fire_time.tv_sec * 1000 + 752 check->last_fire_time.tv_usec / 1000)) < check->period) goto cleanup; 753 754 /* update the last fire time... */ 755 gettimeofday(&check->last_fire_time, NULL); 756 741 757 for(; var != NULL; var = var->next_variable) 742 758 if(noit_snmp_trapvars_to_stats(¤t, var) == 0) success++; … … 762 778 void *magic) { 763 779 struct check_info *info; 764 struct target_session *ts = magic;765 766 780 /* We don't deal with refcnt hitting zero here. We could only be hit from 767 781 * the snmp read/timeout stuff. Handle it there. 768 782 */ 769 ts->refcnt--;770 783 771 784 info = get_check(reqid); 772 785 if(!info) return 1; 786 if(info->ts) { 787 info->ts->refcnt--; 788 info->ts = NULL; 789 } 773 790 remove_check(info); 774 791 if(info->timeoutevent) { … … 800 817 sess.callback_magic = ts; 801 818 ts->sess_handle = snmp_sess_open(&sess); 819 gettimeofday(&ts->last_open, NULL); 802 820 } 803 821 … … 909 927 (info->reqid = snmp_sess_send(ts->sess_handle, req)) != 0) { 910 928 struct timeval when, to; 929 info->ts = ts; 911 930 info->timeoutevent = eventer_alloc(); 912 931 info->timeoutevent->callback = noit_snmp_check_timeout; … … 987 1006 } 988 1007 1008 static void 1009 nc_printf_snmpts_brief(noit_console_closure_t ncct, 1010 struct target_session *ts) { 1011 struct timeval now, diff; 1012 gettimeofday(&now, NULL); 1013 sub_timeval(now, ts->last_open, &diff); 1014 nc_printf(ncct, "[%s]\n\topened: %0.3fs ago\n\tFD: %d\n\trefcnt: %d\n", 1015 ts->target, diff.tv_sec + (float)diff.tv_usec/1000000, 1016 ts->fd, ts->refcnt); 1017 } 1018 1019 static int 1020 noit_console_show_snmp(noit_console_closure_t ncct, 1021 int argc, char **argv, 1022 noit_console_state_t *dstate, 1023 void *closure) { 1024 noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 1025 uuid_t key_id; 1026 int klen; 1027 void *vts; 1028 snmp_mod_config_t *conf = closure; 1029 1030 while(noit_hash_next(&conf->target_sessions, &iter, 1031 (const char **)key_id, &klen, 1032 &vts)) { 1033 struct target_session *ts = vts; 1034 nc_printf_snmpts_brief(ncct, ts); 1035 } 1036 return 0; 1037 } 1038 1039 static void 1040 register_console_snmp_commands(snmp_mod_config_t *conf) { 1041 noit_console_state_t *tl; 1042 cmd_info_t *showcmd; 1043 1044 tl = noit_console_state_initial(); 1045 showcmd = noit_console_state_get_cmd(tl, "show"); 1046 assert(showcmd && showcmd->dstate); 1047 noit_console_state_add_cmd(showcmd->dstate, 1048 NCSCMD("snmp", noit_console_show_snmp, NULL, NULL, conf)); 1049 } 1050 989 1051 static int noit_snmp_init(noit_module_t *self) { 990 1052 const char *opt; … … 999 1061 init_snmp("noitd"); 1000 1062 __snmp_initialize_once = 1; 1063 } 1064 if(strcmp(self->hdr.name, "snmp") == 0) { 1065 register_console_snmp_commands(conf); 1001 1066 } 1002 1067
