Python APIs are used to assemble a syslog message which, in SR OS, has the format described in section Syslog.
Table: Manipulating Python syslog messages describes Python information that can be used to manipulate syslog messages.
Imported Nokia (ALC) modules | Access rights | Comments |
---|---|---|
event (from alc import event) |
— |
The method used to retrieve generic event information. |
syslog (from alc import syslog) |
— |
The method used to retrieve syslog-specific parameters. |
system (from alc import system) |
— |
The method used to retrieve system-specific information. Currently, the only parameter retrieved is the system name. |
Events use the following format as they are written into memory, file, console, and system: nnnn <time> <severity>:<application> # <event_id> <router-name> <subject> <message> The event-related information received in the context data from the log manager is retrieved via the following Python methods: |
||
event.sequence |
RO |
The sequence number of the event (nnnn). |
event.timestamp |
RO |
The timestamp of the event. (YYYY/MM/DD HH:MM:SS.SS). |
event.routerName |
RO |
The router name, for example, BASE, VPRN1, and so on. |
event.application |
RO |
The application generating the event, for example, NA. |
event.severity |
RO |
The severity of the event. This is configurable in SR OS (CLEARED [1], INFO [2], CRITICAL [3], MAJOR [4], MINOR [5], WARNING [6]). |
event.eventId |
RO |
The event ID, for example, 2012. |
event.eventName |
RO |
The event Name, for example, tmnxNatPlBloclAllocationLsn. |
event.subject |
RO |
An optional field, for example, [NAT]. |
event.message |
RO |
The event-specific message, for example, "{2} Map 192.168.20.29 [2001-2005] MDA 1/2 -- 276824064 classic-lsn-sub %3 vprn1 10.10.10.101 at 2015/08/31 09:20:15". |
Syslog methods |
||
syslog.hostName |
RO |
The IP address of the SR OS node sending the syslog message. This is used in the Syslog HEADER. |
syslog.logPrefix |
RO |
The log prefix which is configurable and optional, for example, TMNX: |
syslog.severityToPRI(event.severity) |
— |
The Python method used to derive the PRI field in syslog header based on event severity and a configurable syslog facility. |
syslog.severityToName(event.severity) |
— |
An SR OS event severity to syslog severity name. For more information, see the Syslog section. |
syslog.timestampToUnix(timestamp) |
— |
The Python method that takes a timestamp in the format if YYYY/MM/DD HH:MM:SS and converts it into a UNIX-based format (seconds from Jan 01 1970 – UTC). |
syslog.set(newSyslogPdu) |
— |
The Python method used to send the syslog message in the newSyslogPdu. This variable must be constructed manually via string manipulation. In the absence of the command, the SR OS assembles the default syslog message (as if Python was not configured) and sends it to the syslog server, assuming that the message is not explicitly dropped. |
syslog.drop() |
— |
The Python method used to drop a syslog message. This method must be called before the syslog.set<newSyslogPdu method. |
System methods |
||
system.name |
RO |
The Python method used to retrieve the system name |
For example, assume that the syslog format is:
<PRI><timestamp> <hostname> <log-prefix>: <sequence> <router-name> <appid>-
<severity>-<name>-<eventid> [<subject>]: <text>
Then the following is an example of the syslogPdu constructed via Python:
syslogPdu = "<" + syslog.severityToPRI(event.severity) + ">" \ + event.timestamp + "
" \ + syslog.hostname + " " + syslog.logPrefix + ": " + \ event.sequence + " " + ev
ent.routerName + " " + \ event.application + "-
" + \ syslog.severityToName(event.severity) + "-" + \
event.eventName + "-" + event.eventId + " [" + \
event.subject + "]: " + event.message