Support multiple notifications when sending snmo v2 traps

This commit is contained in:
Mico Micic 2024-08-26 22:01:46 +02:00 committed by Olof Hagsand
parent 302d61d1d1
commit 4553419cc2

View file

@ -230,10 +230,10 @@ done:
* The OID is read from the YANG definition. If the notification contains data, all values * 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. * are bound to the corresponding OIDs and sent with the snmp trap.
* *
* @param[in] s Socket * @param[in] h Clixon handle
* @param[in] arg expected to be clixon_handle * @param[in] xn Notification data received from backend
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
snmp_publish_notification(clixon_handle h, snmp_publish_notification(clixon_handle h,
@ -292,6 +292,7 @@ snmp_stream_cb(int s,
clixon_handle h = (clixon_handle)arg; clixon_handle h = (clixon_handle)arg;
int eof; int eof;
cxobj *xtop = NULL; /* top xml */ cxobj *xtop = NULL; /* top xml */
cxobj *xncont = NULL; /* notification content xml */
cxobj *xn; /* notification xml */ cxobj *xn; /* notification xml */
cbuf *cbmsg = NULL; cbuf *cbmsg = NULL;
int ret; int ret;
@ -313,11 +314,13 @@ snmp_stream_cb(int s,
clixon_err(OE_XML, EFAULT, "Invalid notification"); clixon_err(OE_XML, EFAULT, "Invalid notification");
goto done; goto done;
} }
if ((xn = xpath_first(xtop, NULL, "notification")) == NULL) /* forward notification(s) as snmp trap */
goto ok; while ((xncont = xml_child_each(xtop, xncont, CX_ELMNT)) != NULL){
/* forward notification as snmp trap */ if (strcmp(xml_name(xncont), "notification") == 0) {
if(snmp_publish_notification(h, xn) < 0) if(snmp_publish_notification(h, xncont) < 0)
goto done; goto done;
}
}
ok: ok:
retval = 0; retval = 0;