ldap-agent.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /* --- BEGIN COPYRIGHT BLOCK ---
  2. * Copyright (C) 2005 Red Hat, Inc.
  3. * All rights reserved.
  4. * --- END COPYRIGHT BLOCK --- */
  5. #include <stdio.h>
  6. #include <time.h>
  7. #include "ldap-agent.h"
  8. static netsnmp_handler_registration *ops_handler = NULL;
  9. static netsnmp_handler_registration *entries_handler = NULL;
  10. static netsnmp_handler_registration *entity_handler = NULL;
  11. static netsnmp_table_array_callbacks ops_cb;
  12. static netsnmp_table_array_callbacks entries_cb;
  13. static netsnmp_table_array_callbacks entity_cb;
  14. extern server_instance *server_head;
  15. /* Set table oids */
  16. oid dsOpsTable_oid[] = { dsOpsTable_TABLE_OID };
  17. size_t dsOpsTable_oid_len = OID_LENGTH(dsOpsTable_oid);
  18. oid dsEntriesTable_oid[] = { dsEntriesTable_TABLE_OID };
  19. size_t dsEntriesTable_oid_len = OID_LENGTH(dsEntriesTable_oid);
  20. oid dsEntityTable_oid[] = {dsEntityTable_TABLE_OID };
  21. size_t dsEntityTable_oid_len = OID_LENGTH(dsEntityTable_oid);
  22. /* Set trap oids */
  23. oid snmptrap_oid[] = { snmptrap_OID };
  24. size_t snmptrap_oid_len = OID_LENGTH(snmptrap_oid);
  25. oid enterprise_oid[] = { enterprise_OID };
  26. size_t enterprise_oid_len = OID_LENGTH(enterprise_oid);
  27. /************************************************************
  28. * init_ldap_agent
  29. *
  30. * Initializes the agent and populates the stats table
  31. * with initial data.
  32. */
  33. void
  34. init_ldap_agent(void)
  35. {
  36. server_instance *serv_p = NULL;
  37. stats_table_context *new_row = NULL;
  38. int err;
  39. int stats_hdl = -1;
  40. /* Define and create the table */
  41. initialize_stats_table();
  42. /* Initialize data for each server in conf file */
  43. for (serv_p = server_head; serv_p != NULL; serv_p = serv_p->next) {
  44. /* Check if this row already exists. */
  45. if ((new_row = stats_table_find_row(serv_p->port)) == NULL) {
  46. /* Create a new row */
  47. if ((new_row = stats_table_create_row(serv_p->port)) != NULL) {
  48. /* Set pointer for entity table */
  49. new_row->entity_tbl = serv_p;
  50. /* Set previous state of server to unknown */
  51. serv_p->server_state = STATE_UNKNOWN;
  52. /* Insert new row into the table */
  53. snmp_log(LOG_DEBUG, "Inserting row for server: %d\n", serv_p->port);
  54. CONTAINER_INSERT(ops_cb.container, new_row);
  55. } else {
  56. /* error during malloc of row */
  57. snmp_log(LOG_ERR, "Error creating row for server: %d\n",
  58. serv_p->port);
  59. }
  60. }
  61. }
  62. /* Force load data into stats table */
  63. load_stats_table(NULL, NULL);
  64. }
  65. /************************************************************
  66. * initialize_stats_table
  67. *
  68. * Initializes the stats table by defining its contents,
  69. * how it's structured, and registering callbacks.
  70. */
  71. void
  72. initialize_stats_table(void)
  73. {
  74. netsnmp_table_registration_info *ops_table_info = NULL;
  75. netsnmp_table_registration_info *entries_table_info = NULL;
  76. netsnmp_table_registration_info *entity_table_info = NULL;
  77. netsnmp_cache *stats_table_cache = NULL;
  78. if (ops_handler || entries_handler || entity_handler) {
  79. snmp_log(LOG_ERR, "initialize_stats_table called more than once.\n");
  80. return;
  81. }
  82. memset(&ops_cb, 0x00, sizeof(ops_cb));
  83. memset(&entries_cb, 0x00, sizeof(entries_cb));
  84. memset(&entity_cb, 0x00, sizeof(entity_cb));
  85. /* create table structures */
  86. ops_table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
  87. entries_table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
  88. entity_table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
  89. /* create handlers */
  90. ops_handler = netsnmp_create_handler_registration("dsOpsTable",
  91. netsnmp_table_array_helper_handler,
  92. dsOpsTable_oid,
  93. dsOpsTable_oid_len,
  94. HANDLER_CAN_RONLY);
  95. entries_handler = netsnmp_create_handler_registration("dsEntriesTable",
  96. netsnmp_table_array_helper_handler,
  97. dsEntriesTable_oid,
  98. dsEntriesTable_oid_len,
  99. HANDLER_CAN_RONLY);
  100. entity_handler = netsnmp_create_handler_registration("dsEntityTable",
  101. netsnmp_table_array_helper_handler,
  102. dsEntityTable_oid,
  103. dsEntityTable_oid_len,
  104. HANDLER_CAN_RONLY);
  105. if (!ops_handler || !entries_handler || !entity_handler ||
  106. !ops_table_info || !entries_table_info || !entity_table_info) {
  107. /* malloc failed */
  108. snmp_log(LOG_ERR, "malloc failed in initialize_stats_table\n");
  109. return;
  110. }
  111. /* define table structures */
  112. netsnmp_table_helper_add_index(ops_table_info, ASN_INTEGER);
  113. netsnmp_table_helper_add_index(entries_table_info, ASN_INTEGER);
  114. netsnmp_table_helper_add_index(entity_table_info, ASN_INTEGER);
  115. ops_table_info->min_column = dsOpsTable_COL_MIN;
  116. ops_table_info->max_column = dsOpsTable_COL_MAX;
  117. entries_table_info->min_column = dsEntriesTable_COL_MIN;
  118. entries_table_info->max_column = dsEntriesTable_COL_MAX;
  119. entity_table_info->min_column = dsEntityTable_COL_MIN;
  120. entity_table_info->max_column = dsEntityTable_COL_MAX;
  121. /*
  122. * Define callbacks and the container. We only use one container that
  123. * all of the tables use.
  124. */
  125. ops_cb.get_value = dsOpsTable_get_value;
  126. ops_cb.container = netsnmp_container_find("dsOpsTable_primary:"
  127. "dsOpsTable:" "table_container");
  128. entries_cb.get_value = dsEntriesTable_get_value;
  129. entries_cb.container = ops_cb.container;
  130. entity_cb.get_value = dsEntityTable_get_value;
  131. entity_cb.container = ops_cb.container;
  132. /* registering the tables with the master agent */
  133. netsnmp_table_container_register(ops_handler, ops_table_info, &ops_cb,
  134. ops_cb.container, 1);
  135. netsnmp_table_container_register(entries_handler, entries_table_info, &entries_cb,
  136. entries_cb.container, 1);
  137. netsnmp_table_container_register(entity_handler, entity_table_info, &entity_cb,
  138. entity_cb.container, 1);
  139. /* Setup cache for auto reloading of stats */
  140. stats_table_cache = netsnmp_cache_create(CACHE_REFRESH_INTERVAL, load_stats_table,
  141. NULL, dsOpsTable_oid, dsOpsTable_oid_len);
  142. stats_table_cache->flags |= NETSNMP_CACHE_DONT_FREE_EXPIRED;
  143. stats_table_cache->flags |= NETSNMP_CACHE_DONT_AUTO_RELEASE;
  144. stats_table_cache->flags |= NETSNMP_CACHE_AUTO_RELOAD;
  145. netsnmp_inject_handler(ops_handler, netsnmp_cache_handler_get(stats_table_cache));
  146. }
  147. /************************************************************
  148. * stats_table_create_row
  149. *
  150. * Creates a new table row using the supplied port number as
  151. * the index, then returns a pointer to the new row.
  152. */
  153. stats_table_context *
  154. stats_table_create_row(unsigned long portnum)
  155. {
  156. netsnmp_index index;
  157. stats_table_context *ctx = SNMP_MALLOC_TYPEDEF(stats_table_context);
  158. oid *index_oid = (oid *)malloc(sizeof(oid) * MAX_OID_LEN);
  159. /* Create index using port number */
  160. index_oid[0] = portnum;
  161. index.oids = index_oid;
  162. index.len = 1;
  163. /* Copy index into row structure */
  164. if (ctx && index_oid) {
  165. memcpy(&ctx->index, &index, sizeof(index));
  166. return ctx;
  167. } else {
  168. /* Error during malloc */
  169. snmp_log(LOG_ERR, "malloc failed in stats_table_create_row\n");
  170. return NULL;
  171. }
  172. }
  173. /************************************************************
  174. * stats_table_find_row
  175. *
  176. * Searches for a row by the port number. Returns NULL if
  177. * the row doesn't exist.
  178. */
  179. stats_table_context *
  180. stats_table_find_row(unsigned long portnum)
  181. {
  182. netsnmp_index index;
  183. oid index_oid[MAX_OID_LEN];
  184. index_oid[0] = portnum;
  185. index.oids = index_oid;
  186. index.len = 1;
  187. return (stats_table_context *)
  188. CONTAINER_FIND(ops_cb.container, &index);
  189. }
  190. /************************************************************
  191. * load_stats_table
  192. *
  193. * Reloads the stats into the table. This is called
  194. * automatically from the cache handler. This function
  195. * does not reload the entity table since it's static
  196. * information. We also check if any traps need to
  197. * be sent here.
  198. */
  199. int
  200. load_stats_table(netsnmp_cache *cache, void *foo)
  201. {
  202. server_instance *serv_p = NULL;
  203. stats_table_context *ctx = NULL;
  204. netsnmp_variable_list *vars = NULL;
  205. time_t previous_start;
  206. int previous_state;
  207. int stats_hdl = -1;
  208. int err;
  209. snmp_log(LOG_DEBUG, "Reloading stats.\n");
  210. /* Initialize data for each server in conf file */
  211. for (serv_p = server_head; serv_p != NULL; serv_p = serv_p->next) {
  212. if ((ctx = stats_table_find_row(serv_p->port)) != NULL) {
  213. /* Save previous state of the server to
  214. * see if a trap needs to be sent */
  215. previous_state = serv_p->server_state;
  216. previous_start = ctx->hdr_tbl.startTime;
  217. snmp_log(LOG_DEBUG, "Opening stats file (%s) for server: %d\n",
  218. serv_p->stats_file, serv_p->port);
  219. /* Open the stats file */
  220. if ((err = agt_mopen_stats(serv_p->stats_file, O_RDONLY, &stats_hdl)) != 0) {
  221. /* Server must be down */
  222. serv_p->server_state = SERVER_DOWN;
  223. /* Zero out the ops and entries tables */
  224. memset(&ctx->ops_tbl, 0x00, sizeof(ctx->ops_tbl));
  225. memset(&ctx->entries_tbl, 0x00, sizeof(ctx->entries_tbl));
  226. if (previous_state != SERVER_DOWN)
  227. snmp_log(LOG_INFO, "Unable to open stats file (%s) for server: %d\n",
  228. serv_p->stats_file, serv_p->port);
  229. } else {
  230. /* Initialize ops table */
  231. if ((err = agt_mread_stats(stats_hdl, &ctx->hdr_tbl, &ctx->ops_tbl,
  232. &ctx->entries_tbl)) != 0)
  233. snmp_log(LOG_ERR, "Unable to read stats file: %s\n",
  234. serv_p->stats_file);
  235. /* Close stats file */
  236. if ((err = agt_mclose_stats(stats_hdl)) != 0)
  237. snmp_log(LOG_ERR, "Error closing stats file: %s\n",
  238. serv_p->stats_file);
  239. /* Server must be down if the stats file hasn't been
  240. * updated in a while */
  241. if (difftime(time(NULL), ctx->hdr_tbl.updateTime) >= UPDATE_THRESHOLD) {
  242. serv_p->server_state = SERVER_DOWN;
  243. if (previous_state != SERVER_DOWN)
  244. snmp_log(LOG_INFO, "Stats file for server %d hasn't been updated"
  245. " in %d seconds.\n", serv_p->port, UPDATE_THRESHOLD);
  246. } else {
  247. serv_p->server_state = SERVER_UP;
  248. }
  249. }
  250. /* If the state of the server changed since the last
  251. * load of the stats, send a trap. */
  252. if (previous_state != STATE_UNKNOWN) {
  253. if (serv_p->server_state != previous_state) {
  254. if (serv_p->server_state == SERVER_UP) {
  255. snmp_log(LOG_INFO, "Detected start of server: %d\n",
  256. serv_p->port);
  257. send_DirectoryServerStart_trap(serv_p);
  258. } else {
  259. send_DirectoryServerDown_trap(serv_p);
  260. /* Zero out the ops and entries tables */
  261. memset(&ctx->ops_tbl, 0x00, sizeof(ctx->ops_tbl));
  262. memset(&ctx->entries_tbl, 0x00, sizeof(ctx->entries_tbl));
  263. }
  264. } else if (ctx->hdr_tbl.startTime != previous_start) {
  265. /* Send traps if the server has restarted since the last load */
  266. snmp_log(LOG_INFO, "Detected restart of server: %d\n", serv_p->port);
  267. send_DirectoryServerDown_trap(serv_p);
  268. send_DirectoryServerStart_trap(serv_p);
  269. }
  270. }
  271. } else {
  272. /* Can't find our row. This shouldn't ever happen. */
  273. snmp_log(LOG_ERR, "Row not found for server: %d\n",
  274. serv_p->port);
  275. }
  276. }
  277. return 0;
  278. }
  279. /************************************************************
  280. * dsOpsTable_get_value
  281. *
  282. * This routine is called for get requests to copy the data
  283. * from the context to the varbind for the request. If the
  284. * context has been properly maintained, you don't need to
  285. * change in code in this fuction.
  286. */
  287. int
  288. dsOpsTable_get_value(netsnmp_request_info *request,
  289. netsnmp_index * item,
  290. netsnmp_table_request_info *table_info)
  291. {
  292. netsnmp_variable_list *var = request->requestvb;
  293. stats_table_context *context = (stats_table_context *) item;
  294. switch (table_info->colnum) {
  295. case COLUMN_DSANONYMOUSBINDS:
  296. snmp_set_var_typed_value(var, ASN_COUNTER,
  297. (u_char *) &context->ops_tbl.dsAnonymousBinds,
  298. sizeof(context->ops_tbl.dsAnonymousBinds));
  299. break;
  300. case COLUMN_DSUNAUTHBINDS:
  301. snmp_set_var_typed_value(var, ASN_COUNTER,
  302. (u_char *) &context->ops_tbl.dsUnAuthBinds,
  303. sizeof(context->ops_tbl.dsUnAuthBinds));
  304. break;
  305. case COLUMN_DSSIMPLEAUTHBINDS:
  306. snmp_set_var_typed_value(var, ASN_COUNTER,
  307. (u_char *) &context->ops_tbl.dsSimpleAuthBinds,
  308. sizeof(context->ops_tbl.dsSimpleAuthBinds));
  309. break;
  310. case COLUMN_DSSTRONGAUTHBINDS:
  311. snmp_set_var_typed_value(var, ASN_COUNTER,
  312. (u_char *) &context->ops_tbl.dsStrongAuthBinds,
  313. sizeof(context->ops_tbl.dsStrongAuthBinds));
  314. break;
  315. case COLUMN_DSBINDSECURITYERRORS:
  316. snmp_set_var_typed_value(var, ASN_COUNTER,
  317. (u_char *) &context->ops_tbl.dsBindSecurityErrors,
  318. sizeof(context->ops_tbl.dsBindSecurityErrors));
  319. break;
  320. case COLUMN_DSINOPS:
  321. snmp_set_var_typed_value(var, ASN_COUNTER,
  322. (u_char *) &context->ops_tbl.dsInOps,
  323. sizeof(context->ops_tbl.dsInOps));
  324. break;
  325. case COLUMN_DSREADOPS:
  326. snmp_set_var_typed_value(var, ASN_COUNTER,
  327. (u_char *) &context->ops_tbl.dsReadOps,
  328. sizeof(context->ops_tbl.dsReadOps));
  329. break;
  330. case COLUMN_DSCOMPAREOPS:
  331. snmp_set_var_typed_value(var, ASN_COUNTER,
  332. (u_char *) &context->ops_tbl.dsCompareOps,
  333. sizeof(context->ops_tbl.dsCompareOps));
  334. break;
  335. case COLUMN_DSADDENTRYOPS:
  336. snmp_set_var_typed_value(var, ASN_COUNTER,
  337. (u_char *) &context->ops_tbl.dsAddEntryOps,
  338. sizeof(context->ops_tbl.dsAddEntryOps));
  339. break;
  340. case COLUMN_DSREMOVEENTRYOPS:
  341. snmp_set_var_typed_value(var, ASN_COUNTER,
  342. (u_char *) &context->ops_tbl.dsRemoveEntryOps,
  343. sizeof(context->ops_tbl.dsRemoveEntryOps));
  344. break;
  345. case COLUMN_DSMODIFYENTRYOPS:
  346. snmp_set_var_typed_value(var, ASN_COUNTER,
  347. (u_char *) &context->ops_tbl.dsModifyEntryOps,
  348. sizeof(context->ops_tbl.dsModifyEntryOps));
  349. break;
  350. case COLUMN_DSMODIFYRDNOPS:
  351. snmp_set_var_typed_value(var, ASN_COUNTER,
  352. (u_char *) &context->ops_tbl.dsModifyRDNOps,
  353. sizeof(context->ops_tbl.dsModifyRDNOps));
  354. break;
  355. case COLUMN_DSLISTOPS:
  356. snmp_set_var_typed_value(var, ASN_COUNTER,
  357. (u_char *) &context->ops_tbl.dsListOps,
  358. sizeof(context->ops_tbl.dsListOps));
  359. break;
  360. case COLUMN_DSSEARCHOPS:
  361. snmp_set_var_typed_value(var, ASN_COUNTER,
  362. (u_char *) &context->ops_tbl.dsSearchOps,
  363. sizeof(context->ops_tbl.dsSearchOps));
  364. break;
  365. case COLUMN_DSONELEVELSEARCHOPS:
  366. snmp_set_var_typed_value(var, ASN_COUNTER,
  367. (u_char *) &context->ops_tbl.dsOneLevelSearchOps,
  368. sizeof(context->ops_tbl.dsOneLevelSearchOps));
  369. break;
  370. case COLUMN_DSWHOLESUBTREESEARCHOPS:
  371. snmp_set_var_typed_value(var, ASN_COUNTER,
  372. (u_char *) &context->ops_tbl.dsWholeSubtreeSearchOps,
  373. sizeof(context->ops_tbl.dsWholeSubtreeSearchOps));
  374. break;
  375. case COLUMN_DSREFERRALS:
  376. snmp_set_var_typed_value(var, ASN_COUNTER,
  377. (u_char *) &context->ops_tbl.dsReferrals,
  378. sizeof(context->ops_tbl.dsReferrals));
  379. break;
  380. case COLUMN_DSCHAININGS:
  381. snmp_set_var_typed_value(var, ASN_COUNTER,
  382. (u_char *) &context->ops_tbl.dsChainings,
  383. sizeof(context->ops_tbl.dsChainings));
  384. break;
  385. case COLUMN_DSSECURITYERRORS:
  386. snmp_set_var_typed_value(var, ASN_COUNTER,
  387. (u_char *) &context->ops_tbl.dsSecurityErrors,
  388. sizeof(context->ops_tbl.dsSecurityErrors));
  389. break;
  390. case COLUMN_DSERRORS:
  391. snmp_set_var_typed_value(var, ASN_COUNTER,
  392. (u_char *) &context->ops_tbl.dsErrors,
  393. sizeof(context->ops_tbl.dsErrors));
  394. break;
  395. default:/* We shouldn't get here */
  396. snmp_log(LOG_ERR, "Unknown column in dsOpsTable_get_value\n");
  397. return SNMP_ERR_GENERR;
  398. }
  399. return SNMP_ERR_NOERROR;
  400. }
  401. /************************************************************
  402. * dsEntriesTable_get_value
  403. *
  404. * This routine is called for get requests to copy the data
  405. * from the context to the varbind for the request. If the
  406. * context has been properly maintained, you don't need to
  407. * change in code in this fuction.
  408. */
  409. int
  410. dsEntriesTable_get_value(netsnmp_request_info *request,
  411. netsnmp_index * item,
  412. netsnmp_table_request_info *table_info)
  413. {
  414. netsnmp_variable_list *var = request->requestvb;
  415. stats_table_context *context = (stats_table_context *) item;
  416. switch (table_info->colnum) {
  417. case COLUMN_DSMASTERENTRIES:
  418. snmp_set_var_typed_value(var, ASN_GAUGE,
  419. (u_char *) &context->entries_tbl.dsMasterEntries,
  420. sizeof(context->entries_tbl.dsMasterEntries));
  421. break;
  422. case COLUMN_DSCOPYENTRIES:
  423. snmp_set_var_typed_value(var, ASN_GAUGE,
  424. (u_char *) &context->entries_tbl.dsCopyEntries,
  425. sizeof(context->entries_tbl.dsCopyEntries));
  426. break;
  427. case COLUMN_DSCACHEENTRIES:
  428. snmp_set_var_typed_value(var, ASN_GAUGE,
  429. (u_char *) &context->entries_tbl.dsCacheEntries,
  430. sizeof(context->entries_tbl.dsCacheEntries));
  431. break;
  432. case COLUMN_DSCACHEHITS:
  433. snmp_set_var_typed_value(var, ASN_COUNTER,
  434. (u_char *) &context->entries_tbl.dsCacheHits,
  435. sizeof(context->entries_tbl.dsCacheHits));
  436. break;
  437. case COLUMN_DSSLAVEHITS:
  438. snmp_set_var_typed_value(var, ASN_COUNTER,
  439. (u_char *) &context->entries_tbl.dsSlaveHits,
  440. sizeof(context->entries_tbl.dsSlaveHits));
  441. break;
  442. default:/* We shouldn't get here */
  443. snmp_log(LOG_ERR, "Unknown column in dsEntriesTable_get_value\n");
  444. return SNMP_ERR_GENERR;
  445. }
  446. return SNMP_ERR_NOERROR;
  447. }
  448. /************************************************************
  449. * dsEntityTable_get_value
  450. *
  451. * This routine is called for get requests to copy the data
  452. * from the context to the varbind for the request. If the
  453. * context has been properly maintained, you don't need to
  454. * change in code in this fuction.
  455. */
  456. int
  457. dsEntityTable_get_value(netsnmp_request_info *request,
  458. netsnmp_index * item,
  459. netsnmp_table_request_info *table_info)
  460. {
  461. netsnmp_variable_list *var = request->requestvb;
  462. stats_table_context *context = (stats_table_context *) item;
  463. server_instance *server = (server_instance *) context->entity_tbl;
  464. switch (table_info->colnum) {
  465. case COLUMN_DSENTITYDESCR:
  466. snmp_set_var_typed_value(var, ASN_OCTET_STR,
  467. (u_char *) server->description,
  468. strlen(server->description));
  469. break;
  470. case COLUMN_DSENTITYVERS:
  471. snmp_set_var_typed_value(var, ASN_OCTET_STR,
  472. (u_char *) context->hdr_tbl.dsVersion,
  473. strlen(context->hdr_tbl.dsVersion));
  474. break;
  475. case COLUMN_DSENTITYORG:
  476. snmp_set_var_typed_value(var, ASN_OCTET_STR,
  477. (u_char *) server->org,
  478. strlen(server->org));
  479. break;
  480. case COLUMN_DSENTITYLOCATION:
  481. snmp_set_var_typed_value(var, ASN_OCTET_STR,
  482. (u_char *) server->location,
  483. strlen(server->location));
  484. break;
  485. case COLUMN_DSENTITYCONTACT:
  486. snmp_set_var_typed_value(var, ASN_OCTET_STR,
  487. (u_char *) server->contact,
  488. strlen(server->contact));
  489. break;
  490. case COLUMN_DSENTITYNAME:
  491. snmp_set_var_typed_value(var, ASN_OCTET_STR,
  492. (u_char *) server->name,
  493. strlen(server->name));
  494. break;
  495. default:/* We shouldn't get here */
  496. snmp_log(LOG_ERR, "Unknown column in dsEntityTable_get_value\n");
  497. return SNMP_ERR_GENERR;
  498. }
  499. return SNMP_ERR_NOERROR;
  500. }
  501. /************************************************************
  502. * send_DirectoryServerDown_trap
  503. *
  504. * Sends off the server down trap.
  505. */
  506. int
  507. send_DirectoryServerDown_trap(server_instance *serv_p)
  508. {
  509. netsnmp_variable_list *var_list = NULL;
  510. stats_table_context *ctx = NULL;
  511. /* Define the oids for the trap */
  512. oid DirectoryServerDown_oid[] = { DirectoryServerDown_OID };
  513. oid dsEntityDescr_oid[] = { dsEntityTable_TABLE_OID, 1, COLUMN_DSENTITYDESCR, 0 };
  514. oid dsEntityVers_oid[] = { dsEntityTable_TABLE_OID, 1, COLUMN_DSENTITYVERS, 0 };
  515. oid dsEntityLocation_oid[] = { dsEntityTable_TABLE_OID, 1, COLUMN_DSENTITYLOCATION, 0 };
  516. oid dsEntityContact_oid[] = { dsEntityTable_TABLE_OID, 1, COLUMN_DSENTITYCONTACT, 0 };
  517. dsEntityDescr_oid[3] = serv_p->port;
  518. dsEntityVers_oid[3] = serv_p->port;
  519. dsEntityLocation_oid[3] = serv_p->port;
  520. dsEntityContact_oid[3] = serv_p->port;
  521. snmp_log(LOG_INFO, "Sending down trap for server: %d\n", serv_p->port);
  522. /* Lookup row to get version string */
  523. if ((ctx = stats_table_find_row(serv_p->port)) == NULL) {
  524. snmp_log(LOG_ERR, "Malloc error finding row for server: %d\n", serv_p->port);
  525. return 1;
  526. }
  527. /* Setup the variable list to send with the trap */
  528. snmp_varlist_add_variable(&var_list,
  529. snmptrap_oid, OID_LENGTH(snmptrap_oid),
  530. ASN_OBJECT_ID,
  531. (u_char *) &DirectoryServerDown_oid,
  532. sizeof(DirectoryServerDown_oid));
  533. snmp_varlist_add_variable(&var_list,
  534. dsEntityDescr_oid,
  535. OID_LENGTH(dsEntityDescr_oid), ASN_OCTET_STR,
  536. (u_char *) serv_p->description,
  537. strlen(serv_p->description));
  538. snmp_varlist_add_variable(&var_list,
  539. dsEntityVers_oid,
  540. OID_LENGTH(dsEntityVers_oid), ASN_OCTET_STR,
  541. (u_char *) ctx->hdr_tbl.dsVersion,
  542. strlen(ctx->hdr_tbl.dsVersion));
  543. snmp_varlist_add_variable(&var_list,
  544. dsEntityLocation_oid,
  545. OID_LENGTH(dsEntityLocation_oid),
  546. ASN_OCTET_STR,
  547. (u_char *) serv_p->location,
  548. strlen(serv_p->location));
  549. snmp_varlist_add_variable(&var_list,
  550. dsEntityContact_oid,
  551. OID_LENGTH(dsEntityContact_oid),
  552. ASN_OCTET_STR,
  553. (u_char *) serv_p->contact,
  554. strlen(serv_p->contact));
  555. /* Send the trap */
  556. send_v2trap(var_list);
  557. snmp_free_varbind(var_list);
  558. return SNMP_ERR_NOERROR;
  559. }
  560. /************************************************************
  561. * send_DirectoryServerStart_trap
  562. *
  563. * Sends off the server start trap.
  564. */
  565. int
  566. send_DirectoryServerStart_trap(server_instance *serv_p)
  567. {
  568. netsnmp_variable_list *var_list = NULL;
  569. stats_table_context *ctx = NULL;
  570. /* Define the oids for the trap */
  571. oid DirectoryServerStart_oid[] = { DirectoryServerStart_OID };
  572. oid dsEntityDescr_oid[] = { dsEntityTable_TABLE_OID, 1, COLUMN_DSENTITYDESCR, 0 };
  573. oid dsEntityVers_oid[] = { dsEntityTable_TABLE_OID, 1, COLUMN_DSENTITYVERS, 0 };
  574. oid dsEntityLocation_oid[] = { dsEntityTable_TABLE_OID, 1, COLUMN_DSENTITYLOCATION, 0 };
  575. dsEntityDescr_oid[3] = serv_p->port;
  576. dsEntityVers_oid[3] = serv_p->port;
  577. dsEntityLocation_oid[3] = serv_p->port;
  578. snmp_log(LOG_INFO, "Sending start trap for server: %d\n", serv_p->port);
  579. /* Lookup row to get version string */
  580. if ((ctx = stats_table_find_row(serv_p->port)) == NULL) {
  581. snmp_log(LOG_ERR, "Malloc error finding row for server: %d\n", serv_p->port);
  582. return 1;
  583. }
  584. /* Setup the variable list to send with the trap */
  585. snmp_varlist_add_variable(&var_list,
  586. snmptrap_oid, OID_LENGTH(snmptrap_oid),
  587. ASN_OBJECT_ID,
  588. (u_char *) &DirectoryServerStart_oid,
  589. sizeof(DirectoryServerStart_oid));
  590. snmp_varlist_add_variable(&var_list,
  591. dsEntityDescr_oid,
  592. OID_LENGTH(dsEntityDescr_oid), ASN_OCTET_STR,
  593. (u_char *) serv_p->description,
  594. strlen(serv_p->description));
  595. snmp_varlist_add_variable(&var_list,
  596. dsEntityVers_oid,
  597. OID_LENGTH(dsEntityVers_oid), ASN_OCTET_STR,
  598. (u_char *) ctx->hdr_tbl.dsVersion,
  599. strlen(ctx->hdr_tbl.dsVersion));
  600. snmp_varlist_add_variable(&var_list,
  601. dsEntityLocation_oid,
  602. OID_LENGTH(dsEntityLocation_oid),
  603. ASN_OCTET_STR,
  604. (u_char *) serv_p->location,
  605. strlen(serv_p->location));
  606. /* Send the trap */
  607. send_v2trap(var_list);
  608. snmp_free_varbind(var_list);
  609. return SNMP_ERR_NOERROR;
  610. }