Ok, hopefully, we don't have to rely on Syslog much longer for network management, but, for the time being, let's see how to automate custom Syslog messages. Cisco IOS XR has allowed you to generate custom Syslog messages for quite some time. Historically, those messages were generated using the "logmsg" CLI command:
RP/0/RP0/CPU0:Router#logmsg ?
LINE message to be sent to syslog
RP/0/RP0/CPU0:Router#logmsg A custom syslog message
Tue Dec 13 12:42:36.213 UTC
RP/0/RP0/CPU0:Router#
RP/0/RP0/CPU0:Router#sh log | i syslog
Tue Dec 13 12:43:18.884 UTC
RP/0/RP0/CPU0:Dec 13 12:42:36.296 : logger[65705]: %OS-SYSLOG-6-LOG_INFO : A custom syslog message
RP/0/RP0/CPU0:Router#
|
In the world of data models, we don't want to automate this command using CLI. CIsco IOS XR 6.1.2 already specifies this command in the "Cisco-IOS-XR-syslog-act" YANG model. Now, using YDK 0.5.2 with Cisco-IOS-XR module bundle 6.1.2, you can instantiate an RPC object for this model, provide the input parameter and use the Executor service to execute the RPC. How is it done? Look at these Python sample apps:
nc-execute-xr-syslog-act-20-ydk.py - custom informational message ("A custom informational message")
RP/0/RP0/CPU0:Dec 12 16:20:37.744 : netconf[1101]: %OS-SYSLOG-6-LOG_INFO : A custom informational message
|
nc-execute-xr-syslog-act-22-ydk.py - custom warning message ("A custom warning message")
RP/0/RP0/CPU0:Dec 12 16:27:39.847 : netconf[1101]: %OS-SYSLOG-4-LOG_WARNING : A custom warning message
|
nc-execute-xr-syslog-act-24-ydk.py - custom critical message ("A custom critical message")
RP/0/RP0/CPU0:Dec 12 16:29:47.854 : netconf[1101]: %OS-SYSLOG-2-LOG_CRIT : A custom critical message
|
As always, you can fing a boilerplate app that you can use to create your own:
nc-execute-xr-syslog-act-10-ydk.py - execute boilerplate
Give them a try!