Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

class syslog_utils(object):

    def _init_(self, sylog):        

         // This dictionary will hold the values for the sysconf files for various linux distributions

        self.du = DSHUtils()

   # Syslog conf file data path

    syslog_conf_path = {'centos7rsyslogd': '/etc/rsyslog.conf', 'RHEL7syslog-ng': '/etc/rsyslog'}        // Get OS version of the system /syslog-ng/syslog-ng.conf'}

    # PBS supported severity and facilities
    p_severity = ['info', 'debug']
    p_facility = ['*', 'local7']    

    

    

    def log_syslog_lines(self):

        //This function returns the syslog messages for logmatch

        # get syslog utility running and conf file

        self.cmd_sys = "ps -e | grep syslog | awk '{print $NF}'"

        os = platform.dist()[0] + platform.dist()[1][0]

        path = self.syslog_conf_path[os]

    def path_to_syslog(self):

        // Read the path of the syslog messages file

        // returns the path file as a string

        return path_to_messagesself.utility = self.du.run_cmd(hosts=hostname, cmd=self.cmd_sys, as_script=True, sudo=True,

                                level=logging.DEBUG2)['out']

        self.syslog_conf_file = self.syslog_conf_path.get(self.utility[0])


        #get syslog log files to be read. Currently only sys

        list_of_priority = []

        if self.utility[0] == "rsyslogd":

            list_of_priorities = self.get_rsyslog_priorites()

            self.list_of_syslog_files = self.get_rsyslog_files()

        elif self.utility[0] == "rsyslogd":

            list_of_priorities = self.get_syslogng_priorites()

            self.list_of_syslog_files = self.get_syslogng_files()


       # Get lines from the files

        lines = []

        combined_lines = []

        for x in self.list_of_syslog_files:

            l_sys = self.get_syslog_lines(hostname=hostname, n=n, filename=x, logval=logval)

            #print("l_sys is:")

            #print(l_sys)

            lines.append(l_sys)


        # combine lines from each file

        combined_lines = [item for sublist in lines for item in sublist]

        

        # Sort lines by datetime

        combined_lines.sort(key=lambda x: datetime.datetime.strptime(x[:15], "%b %d %H:%M:%S"))

        return combined_lines

    

    def get_rsyslog_priorites(self, severity=None, facility=None)

        # Returns the priorities. Since the syslog messages can be stored in multiple files, a list is returned

        # If facility and severity mentioned return the file for that combination from rsyslog.conf

        # If severity and facility is NONE read into rsyslog.conf file and return all files that contain the severity set in syslog-ng.conf

        return list_of_priorities[]

   

    

    def get_syslogng_priorites(self, severity=None, facility=None)

        # Returns the priorities. Since the syslog messages can be stored in multiple files, a list is returned

        # If facility and severity mentioned return the file for that combination from rsyslog.conf

        # If severity and facility is NONE read into rsyslog.conf file and return all files that contain the severity set in syslog-ng.conf

        return list_of_priorities[]

    

    def get_rsyslog_files(self)

        # Returns the files to be read. Since the syslog messages can be stored in multiple files, a list is returned

        # If facility and severity mentioned return the file for that combination from rsyslog.conf

        # If severity and facility is NONE read into rsyslog.conf file and return all files that contain the severity set in syslog-ng.conf

        return list_of_files[]


    def get_syslog_ng_files(self)

         # Returns the files to be read. Since the syslog messages can be stored in multiple files, a list is returned

        # If facility and severity mentioned return the file for that combination from syslog-ng.conf

        # If severity and facility is NONE read into rsyslog.conf file and return all files that contain the severity set in syslog-ng.conf

        return list_of_files[]


    def get_syslog_lines(self, hostname=None, n=50, filename=None, logval=None):

        # Return sthe last block of lines from the syslog files for that particular daemon

        # n= number of lines requested by user

        #hostname = host from which to read syslog file

        # file name is the file to read

        

        # is user says all lines, default to 100

        if n == "ALL":

            n=100

        # if hostname is None, default to machine on which ptl is running

        if hostname is None:

            hostname = socket.gethostname()


        if logval is 'sched_logs':

            daemon_str = 'pbs_sched'

        elif logval is 'server_logs':

            daemon_str = 'Server@'

        elif logval is 'mom_logs':

            daemon_str = 'pbs_mom'

        elif logval is 'comm_logs':

            daemon_str = 'pbs_comm'

        else:

            daemon_str = None

       

        # use tail command to get last block of lines from file

        cmd = ['/usr/bin/tail']

        cmd += [str(n), filename]

        lines = self.du.run_cmd(hosts=hostname, cmd=cmd, sudo=True,

                                level=logging.DEBUG2)['out']


        if not(daemon_str is None):

            lines = [l for l in lines if daemon_str in l]

        # return the lines

        return lines


    

    def time_syslog(self):

...

  def _log_match(syslog=False)      if syslog:

         self.init_logfile_path(syslog=true)      lines = self.log_lines(syslog=true)

      rv = self.logutils.match_msg(syslog=true)

  def init_logfile_path(syslog=False)

     if syslog:

        self.syslogUtils = syslog_utils()

        self.logfile = syslog_utils.path_to_syslog() 

 


Note- 'def log_lines' returns the last n lines of the log file.

 def log_lines(syslog=False)

        logval = None

    if syslog:    lines = None

        sudo = False

         selfself.syslogUtils = syslog_utils()


        if syslog:

       filename = syslog_utils.path     logval = self._instance_to_sysloglogpath(logtype)

         sudo = True   lines = self.syslogUtils.log_syslog_lines(hostname=self.hostname, n=n, logval=logval)


——————————In pbs_logutils.py—————————————

...

         if syslog: 

             fmt=    //get format from syslog_config.time_syslog()"%b %d %H:%M:%S"

        try:

             t = time.strptime(datetime, fmt)

...

8) Test that logging via sys logging can be set for only a particular daemon.

...