Python Script to Send Data as Syslog

Document created by hassanvf on Nov 11, 2014
Version 1Show Document
  • View in full screen mode

I was working on a project where we were using python to implement the Web API for a product. One sprint was to send output of our scripts as Syslog to our ArcSight Connector appliance. I wrote the below script .

Just wanted to share if it helps anyone.

 

 

 

import logging

import logging.handlers

 

#Create you logger. Please note that this logger is different from  ArcSight logger.

 

my_logger = logging.getLogger('MyLogger')

 

#We will pass the message as INFO

 

my_logger.setLevel(logging.INFO)

 

#Define SyslogHandler

 

handler = logging.handlers.SysLogHandler(address = ('X.X.X.X',514))

 

#X.X.X.X =IP Address of the Syslog Collector(Connector Appliance,Loggers  etc.)

#514 = Syslog port , You need to specify the port which you have defined ,by default it is 514 for Syslog)

 

my_logger.addHandler(handler)

 

#Example: We will pass values from a List

 

List1 = ['Manchester','Chelsea','Arsenal']

 

for row in List1:

     my_logger.info("I was in " +List1[0])


#We can utilize this method to when we have a CSV to send as Syslog.


#Step 1:     Import the CSV

#Step 2:     Iterate through the CSV row wise

#Step 3:     Send the whole row as syslog


Attachments

    Outcomes