Skip to content

Commit

Permalink
Support multiple notifications when sending snmo v2 traps
Browse files Browse the repository at this point in the history
  • Loading branch information
Mico Micic committed Aug 26, 2024
1 parent 99503ac commit eb76714
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions apps/snmp/snmp_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ add_snmp_var_bindings(netsnmp_variable_list **var_list,
* The OID is read from the YANG definition. If the notification contains data, all values
* are bound to the corresponding OIDs and sent with the snmp trap.
*
* @param[in] s Socket
* @param[in] arg expected to be clixon_handle
* @retval 0 OK
* @retval -1 Error
* @param[in] h Clixon handle
* @param[in] xn Notification data received from backend
* @retval 0 OK
* @retval -1 Error
*/
static int
snmp_publish_notification(clixon_handle h,
Expand Down Expand Up @@ -270,6 +270,7 @@ snmp_stream_cb(int s,
clixon_handle h = (clixon_handle)arg;
int eof;
cxobj *xtop = NULL; /* top xml */
cxobj *xncont = NULL; /* notification content xml */
cxobj *xn; /* notification xml */
cbuf *cbmsg = NULL;
int ret;
Expand All @@ -291,11 +292,13 @@ snmp_stream_cb(int s,
clixon_err(OE_XML, EFAULT, "Invalid notification");
goto done;
}
if ((xn = xpath_first(xtop, NULL, "notification")) == NULL)
goto ok;
/* forward notification as snmp trap */
if(snmp_publish_notification(h, xn) < 0)
goto done;
/* forward notification(s) as snmp trap */
while ((xncont = xml_child_each(xtop, xncont, CX_ELMNT)) != NULL){
if (strcmp(xml_name(xncont), "notification") == 0) {
if(snmp_publish_notification(h, xncont) < 0)
goto done;
}
}

ok:
retval = 0;
Expand Down

0 comments on commit eb76714

Please sign in to comment.