00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <stdio.h>
00040 #include <string.h>
00041 #include <stdlib.h>
00042
00043 #include "../../statistics.h"
00044 #include "../../config.h"
00045
00046 #include <net-snmp/net-snmp-config.h>
00047 #include <net-snmp/net-snmp-includes.h>
00048 #include <net-snmp/agent/net-snmp-agent-includes.h>
00049
00050 #include "openserSIPCommonObjects.h"
00051 #include "snmpstats_globals.h"
00052 #include "utilities.h"
00053
00054 static char *openserVersion = "SIP/2.0";
00055 static unsigned int openserEntityType = TC_SIP_ENTITY_ROLE_OTHER;
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 void init_openserSIPCommonObjects(void)
00066 {
00067 static oid openserSIPProtocolVersion_oid[] =
00068 { OPENSER_OID,3,1,1,1,1,1 };
00069
00070 static oid openserSIPServiceStartTime_oid[] =
00071 { OPENSER_OID,3,1,1,1,1,2 };
00072
00073 static oid openserSIPEntityType_oid[] =
00074 { OPENSER_OID,3,1,1,1,1,4 };
00075
00076 static oid openserSIPSummaryInRequests_oid[] =
00077 { OPENSER_OID,3,1,1,1,3,1 };
00078
00079 static oid openserSIPSummaryOutRequests_oid[] =
00080 { OPENSER_OID,3,1,1,1,3,2 };
00081
00082 static oid openserSIPSummaryInResponses_oid[] =
00083 { OPENSER_OID,3,1,1,1,3,3 };
00084
00085 static oid openserSIPSummaryOutResponses_oid[] =
00086 { OPENSER_OID,3,1,1,1,3,4 };
00087
00088 static oid openserSIPSummaryTotalTransactions_oid[] =
00089 { OPENSER_OID,3,1,1,1,3,5 };
00090
00091 static oid openserSIPCurrentTransactions_oid[] =
00092 { OPENSER_OID,3,1,1,1,6,1 };
00093
00094 static oid openserSIPNumUnsupportedUris_oid[] =
00095 { OPENSER_OID,3,1,1,1,8,1 };
00096
00097 static oid openserSIPNumUnsupportedMethods_oid[] =
00098 { OPENSER_OID,3,1,1,1,8,2 };
00099
00100 static oid openserSIPOtherwiseDiscardedMsgs_oid[] =
00101 { OPENSER_OID,3,1,1,1,8,3 };
00102
00103 DEBUGMSGTL(("openserSIPCommonObjects", "Initializing\n"));
00104
00105 netsnmp_register_scalar(
00106 netsnmp_create_handler_registration(
00107 "openserSIPProtocolVersion",
00108 handle_openserSIPProtocolVersion,
00109 openserSIPProtocolVersion_oid,
00110 OID_LENGTH(openserSIPProtocolVersion_oid),
00111 HANDLER_CAN_RONLY));
00112
00113 netsnmp_register_scalar(
00114 netsnmp_create_handler_registration(
00115 "openserSIPServiceStartTime",
00116 handle_openserSIPServiceStartTime,
00117 openserSIPServiceStartTime_oid,
00118 OID_LENGTH(openserSIPServiceStartTime_oid),
00119 HANDLER_CAN_RONLY));
00120
00121 netsnmp_register_scalar(
00122 netsnmp_create_handler_registration(
00123 "openserSIPEntityType",
00124 handle_openserSIPEntityType,
00125 openserSIPEntityType_oid,
00126 OID_LENGTH(openserSIPEntityType_oid),
00127 HANDLER_CAN_RONLY));
00128
00129 netsnmp_register_scalar(
00130 netsnmp_create_handler_registration(
00131 "openserSIPSummaryInRequests",
00132 handle_openserSIPSummaryInRequests,
00133 openserSIPSummaryInRequests_oid,
00134 OID_LENGTH(openserSIPSummaryInRequests_oid),
00135 HANDLER_CAN_RONLY));
00136
00137 netsnmp_register_scalar(
00138 netsnmp_create_handler_registration(
00139 "openserSIPSummaryOutRequests",
00140 handle_openserSIPSummaryOutRequests,
00141 openserSIPSummaryOutRequests_oid,
00142 OID_LENGTH(openserSIPSummaryOutRequests_oid),
00143 HANDLER_CAN_RONLY));
00144
00145 netsnmp_register_scalar(
00146 netsnmp_create_handler_registration(
00147 "openserSIPSummaryInResponses",
00148 handle_openserSIPSummaryInResponses,
00149 openserSIPSummaryInResponses_oid,
00150 OID_LENGTH(openserSIPSummaryInResponses_oid),
00151 HANDLER_CAN_RONLY));
00152
00153 netsnmp_register_scalar(
00154 netsnmp_create_handler_registration(
00155 "openserSIPSummaryOutResponses",
00156 handle_openserSIPSummaryOutResponses,
00157 openserSIPSummaryOutResponses_oid,
00158 OID_LENGTH(openserSIPSummaryOutResponses_oid),
00159 HANDLER_CAN_RONLY));
00160
00161 netsnmp_register_scalar(
00162 netsnmp_create_handler_registration(
00163 "openserSIPSummaryTotalTransactions",
00164 handle_openserSIPSummaryTotalTransactions,
00165 openserSIPSummaryTotalTransactions_oid,
00166 OID_LENGTH(openserSIPSummaryTotalTransactions_oid),
00167 HANDLER_CAN_RONLY));
00168
00169 netsnmp_register_scalar(
00170 netsnmp_create_handler_registration(
00171 "openserSIPCurrentTransactions",
00172 handle_openserSIPCurrentTransactions,
00173 openserSIPCurrentTransactions_oid,
00174 OID_LENGTH(openserSIPCurrentTransactions_oid),
00175 HANDLER_CAN_RONLY));
00176
00177 netsnmp_register_scalar(
00178 netsnmp_create_handler_registration(
00179 "openserSIPNumUnsupportedUris",
00180 handle_openserSIPNumUnsupportedUris,
00181 openserSIPNumUnsupportedUris_oid,
00182 OID_LENGTH(openserSIPNumUnsupportedUris_oid),
00183 HANDLER_CAN_RONLY));
00184
00185 netsnmp_register_scalar(
00186 netsnmp_create_handler_registration(
00187 "openserSIPNumUnsupportedMethods",
00188 handle_openserSIPNumUnsupportedMethods,
00189 openserSIPNumUnsupportedMethods_oid,
00190 OID_LENGTH(openserSIPNumUnsupportedMethods_oid),
00191 HANDLER_CAN_RONLY));
00192
00193 netsnmp_register_scalar(
00194 netsnmp_create_handler_registration(
00195 "openserSIPOtherwiseDiscardedMsgs",
00196 handle_openserSIPOtherwiseDiscardedMsgs,
00197 openserSIPOtherwiseDiscardedMsgs_oid,
00198 OID_LENGTH(openserSIPOtherwiseDiscardedMsgs_oid),
00199 HANDLER_CAN_RONLY));
00200
00201 }
00202
00203 int handle_openserSIPProtocolVersion(netsnmp_mib_handler *handler,
00204 netsnmp_handler_registration *reginfo,
00205 netsnmp_agent_request_info *reqinfo,
00206 netsnmp_request_info *requests)
00207 {
00208 if (reqinfo->mode==MODE_GET) {
00209 snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
00210 (u_char *) openserVersion, 7);
00211 return SNMP_ERR_NOERROR;
00212 }
00213
00214 return SNMP_ERR_GENERR;
00215 }
00216
00217
00218
00219
00220
00221
00222 int handle_openserSIPServiceStartTime(netsnmp_mib_handler *handler,
00223 netsnmp_handler_registration *reginfo,
00224 netsnmp_agent_request_info *reqinfo,
00225 netsnmp_request_info *requests)
00226 {
00227
00228 int elapsedTime = 0;
00229 char buffer[SNMPGET_MAX_BUFFER];
00230
00231 FILE *theFile = fopen(SNMPGET_TEMP_FILE, "r");
00232
00233
00234
00235 if (theFile == NULL) {
00236 LM_ERR("failed to read sysUpTime file at %s\n",
00237 SNMPGET_TEMP_FILE);
00238 } else {
00239 fgets(buffer, SNMPGET_MAX_BUFFER, theFile);
00240
00241
00242
00243 char *openBracePosition = strchr(buffer, '(');
00244 char *closedBracePosition = strchr(buffer, ')');
00245
00246
00247
00248
00249
00250 if (openBracePosition != NULL && closedBracePosition != NULL &&
00251 openBracePosition < closedBracePosition) {
00252 elapsedTime = (int) strtol(++openBracePosition, NULL, 10);
00253 }
00254
00255 fclose(theFile);
00256 }
00257
00258 if (reqinfo->mode == MODE_GET) {
00259 snmp_set_var_typed_value(requests->requestvb, ASN_TIMETICKS,
00260 (u_char *) &elapsedTime, sizeof(elapsedTime));
00261 return SNMP_ERR_NOERROR;
00262 }
00263
00264 return SNMP_ERR_GENERR;
00265 }
00266
00267
00268 int handle_openserSIPEntityType(netsnmp_mib_handler *handler,
00269 netsnmp_handler_registration *reginfo,
00270 netsnmp_agent_request_info *reqinfo,
00271 netsnmp_request_info *requests)
00272 {
00273 if (reqinfo->mode==MODE_GET) {
00274 snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
00275 (u_char *) &openserEntityType, 1);
00276 return SNMP_ERR_NOERROR;
00277 }
00278
00279 return SNMP_ERR_GENERR;
00280 }
00281
00282
00283 int handle_openserSIPSummaryInRequests(netsnmp_mib_handler *handler,
00284 netsnmp_handler_registration *reginfo,
00285 netsnmp_agent_request_info *reqinfo,
00286 netsnmp_request_info *requests)
00287 {
00288 int numRequests = get_statistic("rcv_requests");
00289
00290 if (reqinfo->mode==MODE_GET) {
00291 snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
00292 (u_char *) &numRequests, sizeof(int));
00293 return SNMP_ERR_NOERROR;
00294 }
00295
00296 return SNMP_ERR_GENERR;
00297 }
00298
00299 int handle_openserSIPSummaryOutRequests(netsnmp_mib_handler *handler,
00300 netsnmp_handler_registration *reginfo,
00301 netsnmp_agent_request_info *reqinfo,
00302 netsnmp_request_info *requests)
00303 {
00304 int out_requests = get_statistic("fwd_requests");
00305
00306 if (reqinfo->mode==MODE_GET) {
00307 snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
00308 (u_char *) &out_requests, sizeof(int));
00309 return SNMP_ERR_NOERROR;
00310 }
00311
00312 return SNMP_ERR_GENERR;
00313 }
00314
00315 int handle_openserSIPSummaryInResponses(netsnmp_mib_handler *handler,
00316 netsnmp_handler_registration *reginfo,
00317 netsnmp_agent_request_info *reqinfo,
00318 netsnmp_request_info *requests)
00319 {
00320 int result = get_statistic("rcv_replies");
00321
00322 if (reqinfo->mode==MODE_GET) {
00323 snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
00324 (u_char *) &result, sizeof(int));
00325 return SNMP_ERR_NOERROR;
00326 }
00327
00328 return SNMP_ERR_GENERR;
00329 }
00330
00331 int handle_openserSIPSummaryOutResponses(netsnmp_mib_handler *handler,
00332 netsnmp_handler_registration *reginfo,
00333 netsnmp_agent_request_info *reqinfo,
00334 netsnmp_request_info *requests)
00335 {
00336
00337
00338
00339
00340
00341
00342
00343
00344 int fwd_replies = get_statistic("fwd_replies");
00345 int local_replies = get_statistic("local_replies");
00346 int relayed_replies = get_statistic("relayed_replies");
00347 int sent_replies = get_statistic("sent_replies");
00348
00349 int result =
00350 fwd_replies + local_replies + relayed_replies + sent_replies;
00351
00352 if (reqinfo->mode==MODE_GET) {
00353 snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
00354 (u_char *) &result, sizeof(int));
00355 return SNMP_ERR_NOERROR;
00356 }
00357
00358 return SNMP_ERR_GENERR;
00359 }
00360
00361 int handle_openserSIPSummaryTotalTransactions(netsnmp_mib_handler *handler,
00362 netsnmp_handler_registration *reginfo,
00363 netsnmp_agent_request_info *reqinfo,
00364 netsnmp_request_info *requests)
00365 {
00366
00367
00368
00369
00370 int result =
00371 get_statistic("UAS_transactions") +
00372 get_statistic("UAC_transactions");
00373
00374 if (reqinfo->mode==MODE_GET) {
00375 snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
00376 (u_char *) &result, sizeof(int));
00377 return SNMP_ERR_NOERROR;
00378 }
00379
00380 return SNMP_ERR_GENERR;
00381 }
00382
00383 int handle_openserSIPCurrentTransactions(netsnmp_mib_handler *handler,
00384 netsnmp_handler_registration *reginfo,
00385 netsnmp_agent_request_info *reqinfo,
00386 netsnmp_request_info *requests)
00387 {
00388 int result = get_statistic("inuse_transactions");
00389
00390 if (reqinfo->mode==MODE_GET) {
00391 snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE,
00392 (u_char *) &result, sizeof(int));
00393 return SNMP_ERR_NOERROR;
00394 }
00395
00396 return SNMP_ERR_GENERR;
00397 }
00398
00399 int handle_openserSIPNumUnsupportedUris(netsnmp_mib_handler *handler,
00400 netsnmp_handler_registration *reginfo,
00401 netsnmp_agent_request_info *reqinfo,
00402 netsnmp_request_info *requests)
00403 {
00404 int result = get_statistic("bad_URIs_rcvd");
00405
00406 if (reqinfo->mode==MODE_GET) {
00407 snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
00408 (u_char *) &result, sizeof(int));
00409 return SNMP_ERR_NOERROR;
00410 }
00411
00412 return SNMP_ERR_GENERR;
00413 }
00414
00415 int handle_openserSIPNumUnsupportedMethods(netsnmp_mib_handler *handler,
00416 netsnmp_handler_registration *reginfo,
00417 netsnmp_agent_request_info *reqinfo,
00418 netsnmp_request_info *requests)
00419 {
00420 int result = get_statistic("unsupported_methods");
00421
00422 if (reqinfo->mode==MODE_GET) {
00423 snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
00424 (u_char *) &result, sizeof(int));
00425 return SNMP_ERR_NOERROR;
00426 }
00427
00428 return SNMP_ERR_GENERR;
00429 }
00430
00431 int handle_openserSIPOtherwiseDiscardedMsgs(netsnmp_mib_handler *handler,
00432 netsnmp_handler_registration *reginfo,
00433 netsnmp_agent_request_info *reqinfo,
00434 netsnmp_request_info *requests)
00435 {
00436
00437
00438 int result =
00439 get_statistic("err_requests") +
00440 get_statistic("err_replies") +
00441 get_statistic("drop_requests") +
00442 get_statistic("drop_replies");
00443
00444 if (reqinfo->mode==MODE_GET) {
00445 snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
00446 (u_char *) &result, sizeof(int));
00447 return SNMP_ERR_NOERROR;
00448 }
00449
00450 return SNMP_ERR_GENERR;
00451 }
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464 int handleSipEntityType( modparam_t type, void* val)
00465 {
00466
00467
00468 static char firstTime = 1;
00469
00470 if (!stringHandlerSanityCheck(type, val, "sipEntityType")) {
00471 return -1;
00472 }
00473
00474 char *strEntityType = (char *)val;
00475
00476
00477
00478
00479 if (firstTime) {
00480 firstTime = 0;
00481 openserEntityType = 0;
00482 }
00483
00484
00485
00486
00487
00488 if (strcasecmp(strEntityType, "other") == 0) {
00489 openserEntityType |= TC_SIP_ENTITY_ROLE_OTHER;
00490 }
00491 else if (strcasecmp(strEntityType, "userAgent") == 0) {
00492 openserEntityType |= TC_SIP_ENTITY_ROLE_USER_AGENT;
00493 }
00494 else if (strcasecmp(strEntityType, "proxyServer") == 0) {
00495 openserEntityType |= TC_SIP_ENTITY_ROLE_PROXY_SERVER;
00496 }
00497 else if (strcasecmp(strEntityType, "redirectServer") == 0) {
00498 openserEntityType |= TC_SIP_ENTITY_ROLE_REDIRECT_SERVER;
00499 }
00500 else if (strcasecmp(strEntityType, "registrarServer") == 0) {
00501 openserEntityType |= TC_SIP_ENTITY_ROLE_REGISTRAR_SERVER;
00502 }
00503 else {
00504 LM_ERR("The configuration file specified sipEntityType=%s,"
00505 " an unknown type\n", strEntityType);
00506 return -1;
00507 }
00508
00509 return 0;
00510 }