[c5c522c] | 1 | /* |
---|
| 2 | * Note: this file originally auto-generated by mib2c using |
---|
| 3 | * version : 15795 $ of $ |
---|
| 4 | */ |
---|
| 5 | /* standard Net-SNMP includes */ |
---|
| 6 | #include <net-snmp/net-snmp-config.h> |
---|
| 7 | #include <net-snmp/net-snmp-includes.h> |
---|
| 8 | #include <net-snmp/agent/net-snmp-agent-includes.h> |
---|
| 9 | |
---|
| 10 | /* include our parent header */ |
---|
| 11 | #include "syn3Version.h" |
---|
| 12 | #include "syn3FacilitiesTable/syn3FacilitiesTable.h" |
---|
| 13 | #include "syn3StatisticsTable/syn3StatisticsTable.h" |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | #include <signal.h> |
---|
| 17 | |
---|
| 18 | static int keep_running; |
---|
| 19 | |
---|
| 20 | static RETSIGTYPE |
---|
| 21 | stop_server(int a) { |
---|
| 22 | keep_running = 0; |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | static void usage(void) { |
---|
| 26 | printf("usage: syn3_snmp_subagent [-D<tokens>] [-f] [-L] [-M] [-H] [LISTENING ADDRESSES]\n" |
---|
| 27 | "\t-f Do not fork() from the calling shell.\n" |
---|
| 28 | "\t-DTOKEN[,TOKEN,...]\n" |
---|
| 29 | "\t\tTurn on debugging output for the given TOKEN(s).\n" |
---|
| 30 | "\t\tWithout any tokens specified, it defaults to printing\n" |
---|
| 31 | "\t\tall the tokens (which is equivalent to the keyword 'ALL').\n" |
---|
| 32 | "\t\tYou might want to try ALL for extremely verbose output.\n" |
---|
| 33 | "\t\tNote: You can't put a space between the -D and the TOKENs.\n" |
---|
| 34 | "\t-H\tDisplay a list of configuration file directives\n" |
---|
| 35 | "\t\tunderstood by the agent and then exit.\n" |
---|
| 36 | "\t-M\tRun as a normal SNMP Agent instead of an AgentX sub-agent.\n" |
---|
| 37 | "\t-x ADDRESS\tconnect to master agent at ADDRESS (default /var/agentx/master).\n" |
---|
| 38 | "\t-L\tDo not open a log file; print all messages to stderr.\n"); |
---|
| 39 | exit(0); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | int |
---|
| 43 | main (int argc, char **argv) { |
---|
| 44 | int agentx_subagent=1; /* change this if you want to be a SNMP master agent */ |
---|
| 45 | /* Defs for arg-handling code: handles setting of policy-related variables */ |
---|
| 46 | int ch; |
---|
| 47 | extern char *optarg; |
---|
| 48 | int dont_fork = 0, use_syslog = 0; |
---|
| 49 | char *agentx_socket = NULL; |
---|
| 50 | |
---|
| 51 | while ((ch = getopt(argc, argv, "D:fHLMx:")) != EOF) |
---|
| 52 | switch(ch) { |
---|
| 53 | case 'D': |
---|
| 54 | debug_register_tokens(optarg); |
---|
| 55 | snmp_set_do_debugging(1); |
---|
| 56 | break; |
---|
| 57 | case 'f': |
---|
| 58 | dont_fork = 1; |
---|
| 59 | break; |
---|
| 60 | case 'H': |
---|
| 61 | netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, |
---|
| 62 | NETSNMP_DS_AGENT_NO_ROOT_ACCESS, 1); |
---|
| 63 | init_agent("syn3Version"); /* register our .conf handlers */ |
---|
| 64 | init_agent("syn3FacilitiesTable"); /* register our .conf handlers */ |
---|
| 65 | init_agent("syn3StatisticsTable"); /* register our .conf handlers */ |
---|
| 66 | init_syn3Version(); |
---|
| 67 | init_syn3FacilitiesTable(); |
---|
| 68 | init_syn3StatisticsTable(); |
---|
| 69 | init_snmp("syn3Version"); |
---|
| 70 | init_snmp("syn3FacilitiesTable"); |
---|
| 71 | init_snmp("syn3StatisticsTable"); |
---|
| 72 | fprintf(stderr, "Configuration directives understood:\n"); |
---|
| 73 | read_config_print_usage(" "); |
---|
| 74 | exit(0); |
---|
| 75 | case 'M': |
---|
| 76 | agentx_subagent = 0; |
---|
| 77 | break; |
---|
| 78 | case 'L': |
---|
| 79 | use_syslog = 0; /* use stderr */ |
---|
| 80 | break; |
---|
| 81 | case 'x': |
---|
| 82 | agentx_socket = optarg; |
---|
| 83 | break; |
---|
| 84 | default: |
---|
| 85 | fprintf(stderr,"unknown option %c\n", ch); |
---|
| 86 | usage(); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | if (optind < argc) { |
---|
| 90 | int i; |
---|
| 91 | /* |
---|
| 92 | * There are optional transport addresses on the command line. |
---|
| 93 | */ |
---|
| 94 | DEBUGMSGTL(("snmpd/main", "optind %d, argc %d\n", optind, argc)); |
---|
| 95 | for (i = optind; i < argc; i++) { |
---|
| 96 | char *c, *astring; |
---|
| 97 | if ((c = netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID, |
---|
| 98 | NETSNMP_DS_AGENT_PORTS))) { |
---|
| 99 | astring = malloc(strlen(c) + 2 + strlen(argv[i])); |
---|
| 100 | if (astring == NULL) { |
---|
| 101 | fprintf(stderr, "malloc failure processing argv[%d]\n", i); |
---|
| 102 | exit(1); |
---|
| 103 | } |
---|
| 104 | sprintf(astring, "%s,%s", c, argv[i]); |
---|
| 105 | netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, |
---|
| 106 | NETSNMP_DS_AGENT_PORTS, astring); |
---|
| 107 | SNMP_FREE(astring); |
---|
| 108 | } else { |
---|
| 109 | netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, |
---|
| 110 | NETSNMP_DS_AGENT_PORTS, argv[i]); |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | DEBUGMSGTL(("snmpd/main", "port spec: %s\n", |
---|
| 114 | netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID, |
---|
| 115 | NETSNMP_DS_AGENT_PORTS))); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | /* we're an agentx subagent? */ |
---|
| 119 | if (agentx_subagent) { |
---|
| 120 | /* make us a agentx client. */ |
---|
| 121 | netsnmp_enable_subagent(); |
---|
| 122 | if (NULL != agentx_socket) |
---|
| 123 | netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, |
---|
| 124 | NETSNMP_DS_AGENT_X_SOCKET, agentx_socket); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | snmp_disable_log(); |
---|
| 128 | if (use_syslog) |
---|
| 129 | snmp_enable_calllog(); |
---|
| 130 | else |
---|
| 131 | snmp_enable_stderrlog(); |
---|
| 132 | |
---|
| 133 | /* daemonize */ |
---|
| 134 | if(!dont_fork) { |
---|
| 135 | int rc = netsnmp_daemonize(1,!use_syslog); |
---|
| 136 | if(rc) |
---|
| 137 | exit(-1); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | /* initialize tcp/ip if necessary */ |
---|
| 141 | SOCK_STARTUP; |
---|
| 142 | |
---|
| 143 | /* initialize the agent library */ |
---|
| 144 | init_agent("syn3Version"); |
---|
| 145 | init_agent("syn3FacilitiesTable"); |
---|
| 146 | init_agent("syn3StatisticsTable"); |
---|
| 147 | |
---|
| 148 | /* init syn3FacilitiesTable mib code */ |
---|
| 149 | init_syn3Version(); |
---|
| 150 | init_syn3FacilitiesTable(); |
---|
| 151 | init_syn3StatisticsTable(); |
---|
| 152 | |
---|
| 153 | /* read syn3FacilitiesTable.conf files. */ |
---|
| 154 | init_snmp("syn3Version"); |
---|
| 155 | init_snmp("syn3FacilitiesTable"); |
---|
| 156 | init_snmp("syn3StatisticsTable"); |
---|
| 157 | |
---|
| 158 | /* If we're going to be a snmp master agent, initial the ports */ |
---|
| 159 | if (!agentx_subagent) |
---|
| 160 | init_master_agent(); /* open the port to listen on (defaults to udp:161) */ |
---|
| 161 | |
---|
| 162 | /* In case we recevie a request to stop (kill -TERM or kill -INT) */ |
---|
| 163 | keep_running = 1; |
---|
| 164 | signal(SIGTERM, stop_server); |
---|
| 165 | signal(SIGINT, stop_server); |
---|
| 166 | |
---|
| 167 | /* you're main loop here... */ |
---|
| 168 | while(keep_running) { |
---|
| 169 | /* if you use select(), see snmp_select_info() in snmp_api(3) */ |
---|
| 170 | /* --- OR --- */ |
---|
| 171 | agent_check_and_process(1); /* 0 == don't block */ |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | /* at shutdown time */ |
---|
| 175 | snmp_shutdown("syn3Version"); |
---|
| 176 | snmp_shutdown("syn3FacilitiesTable"); |
---|
| 177 | snmp_shutdown("syn3StatisticsTable"); |
---|
| 178 | SOCK_CLEANUP; |
---|
| 179 | exit(0); |
---|
| 180 | } |
---|
| 181 | |
---|