Configuring NXlog with python

Hello folks,
I’ve finally started working with python for one of our new automatization systems, saltstack. I’ve been experimenting with saltstack recently so I don’t have much experience in this technology. Anyway, I’ve created a script that allows you to configure a log aggregation server (such as Graylog or Flume) on your NXlog client. The script verifies if a hostname or IP address is already configured using a regex formula and if a configuration is not found, allows you to configure the server:

import re
import logging
import subprocess

logger = logging.getLogger(__name__)

def checkconf():
    k = 0
    file = ‘C:\\Program Files (x86)\\nxlog\\conf\\nxlog.conf’
    for line in f:
        if re.match(“^\s*Host\s*([a-z]|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})”, line):
            k = 1
    if k == 1:
        return True
        return False

def set(flumeip=”″):
    configfile = ‘C:\\Program Files (x86)\\nxlog\\conf\\nxlog.conf’
    oldpattern = “Host “
    newpattern = “Host ” + flumeip

    if checkconf() == True:“Nxlog configuration already found, skipping”)
        f = open(configfile,’r’)
        filedata =
        newdata = filedata.replace(oldpattern,newpattern)
        f = open(configfile,’w’)
        f.close()‘net stop “nxlog”‘)“NXlog service Stopped”)‘net start “nxlog”‘)“NXlog service Started”)“IP configured for the NXlog client”)
        return True

checkconf() function verifies if the server is already configured and returns either True or False if a match is found or not.
set() function checks the returned value of checkconf() and then either skips the configuration if a match is found or adds the IP/hostname and then restarts the NXlog service.
That’s about all for this article, if you have any misunderstandings don’t hesitate to post a comment in my dedicated section.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s