[Yum] Yum cron defaults

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Garrick Staples wrote:

> The "hooks" are called stdout. Just make the cronjob do whatever you want.
>
>yum ... | whateveryouwant
>yum update | logger -t yum
>etc...
>

Let me think - I should write a wrapper processing yum output and trying 
to catch all the lines I want while checking from version to version of 
yum that Seth didn't change any output text that I was trying to parse?  
Or I should send useless text out to the syslog (yum update|logger -t 
yum)?  No thanks :).

I attach a sample patch that adds syslog option in addition to output to 
a file.  Just set syslog_ident=yum in /etc/yum.conf and it should send 
exactly the same text from /var/log/yum.conf also to syslog with ident 
string=yum (or whatever else you choose).  I also made it possible to 
invoke Logger with file_name param so that Logger can take care of 
opening the output file on its own - it is more self contained in this 
way (the open statement before creating logger object  seemed out of 
place, but that's just me :) ).

I'll create a bugzilla entry if Seth thinks it's worth it - it's only 
40ish lines that can be done in many different ways in little time, it 
would be 10 lines with less config opts. I could in that case also add a 
bit of documentation to yum's man page.

Josko P.
-------------- next part --------------
--- yum-2.0.4/logger.py.syslog	2003-10-19 17:49:39.000000000 -0400
+++ yum-2.0.4/logger.py	2004-01-05 23:19:37.000000000 -0500
@@ -144,6 +144,7 @@
 
 import sys
 import string
+import syslog
 
 
 AUTHOR  = "Michael D. Stenner <mstenner@xxxxxxxxxxxx>"
@@ -182,6 +183,8 @@
       ----------------------------------------------------------
       threshold    = 0          how verbose the program should be
       file_object  = sys.stderr file object to which output goes
+      file_name    = None       file name.  If present file_name
+                                is opened and set as file_object
       prefix       = ''         prefix string - repeated for more
                                 important logs
       prefix_depth = 5          times prefix is repeated for logs
@@ -193,19 +196,35 @@
                                 be used (useful for printing time)
       postprefix   = ''         string printed after the prefix
       default      = 1          default priority to log at
+      syslog_ident = None       Syslog identifier, if present also
+                                log messages to syslog
+      syslog_facility = LOG_USER Syslog message facility
+      syslog_priority = LOG_INFO Syslog message priority
 
     """
 
     def __init__(self,
                  threshold    = 0,
                  file_object  = sys.stderr,
+                 file_name    = None,
                  prefix       = '',
                  prefix_depth = 5,
                  preprefix    = '',
                  postprefix   = '',
-                 default      = 1):
+                 default      = 1,
+                 syslog_ident = None,
+                 syslog_facility = syslog.LOG_USER,
+                 syslog_priority = syslog.LOG_INFO):
         self.threshold    = threshold
-        self.file_object  = file_object
+        if file_name:
+            self.file_object = open(file_name,"a")
+        else:
+            self.file_object  = file_object
+        if syslog_ident:
+            self.do_syslog= 1
+            syslog.openlog(syslog_ident, 0, syslog_facility | syslog_priority)
+        else:
+            self.do_syslog= 0
         self.prefix       = prefix
         self.prefix_depth = prefix_depth
         self.preprefix    = preprefix
@@ -254,7 +273,6 @@
         """
         p, m = self._use_default(priority, message)
         if self.test(p):
-            if self.file_object is None: return
             if type(m) == type(''): # message is a string
                 mlist = string.split(m, '\n')
                 if mlist[-1] == '': del mlist[-1] # string ends in \n
@@ -264,7 +282,10 @@
 
             prefix = self.gen_prefix(p)
             for line in mlist:
-                self.file_object.write(prefix + line + '\n')
+                if self.file_object:
+                    self.file_object.write(prefix + line + '\n')
+                if self.do_syslog:
+                    syslog.syslog(line)
 
     # make the objects callable
     __call__ = log
@@ -276,8 +297,10 @@
         """
         p, m = self._use_default(priority, message)
         if self.test(p):
-            if self.file_object is None: return
-            self.file_object.write(m)
+            if self.file_object:
+                self.file_object.write(m)
+            if self.do_syslog:
+                syslog.syslog(m)
 
     def _use_default(self, priority, message):
         """Substitute default priority if none was provided"""
--- yum-2.0.4/yummain.py.syslog	2003-10-19 17:49:39.000000000 -0400
+++ yum-2.0.4/yummain.py	2004-01-05 23:16:26.000000000 -0500
@@ -79,8 +79,9 @@
         log=Logger(threshold=conf.debuglevel, file_object=sys.stdout)
         # syslog-style log
         if conf.uid == 0:
-            logfile=open(conf.logfile,"a")
-            filelog=Logger(threshold=10, file_object=logfile,preprefix=clientStuff.printtime())
+            filelog=Logger(threshold=10, file_name=conf.logfile,preprefix=clientStuff.printtime(), 
+                               syslog_ident=conf.syslog_ident, syslog_priority=conf.syslog_priority, 
+                               syslog_facility=conf.syslog_facility )
         else:
             filelog=Logger(threshold=10, file_object=None,preprefix=clientStuff.printtime())
 
--- yum-2.0.4/config.py.syslog	2003-10-19 17:49:39.000000000 -0400
+++ yum-2.0.4/config.py	2004-01-05 23:16:15.000000000 -0500
@@ -27,6 +27,7 @@
 import archwork
 import rpmUtils
 import progress_meter
+import syslog
 
 from i18n import _
 
@@ -64,6 +65,9 @@
         self.cachedir = '/var/cache/yum'
         self.debuglevel = 2
         self.logfile = '/var/log/yum.log'
+        self.syslog_ident = None
+        self.syslog_facility = syslog.LOG_USER
+        self.syslog_priority = syslog.LOG_INFO
         self.pkgpolicy = 'newest'
         self.assumeyes = 0
         self.errorlevel = 2
@@ -96,6 +100,12 @@
             self.debuglevel = self._getoption('main','debuglevel')
         if self._getoption('main','logfile') != None:
             self.logfile = self._getoption('main','logfile')
+        if self._getoption('main','syslog_ident') != None:
+            self.syslog_ident = self._getoption('main','syslog_ident')
+        if self._getoption('main','syslog_facility') != None:
+            self.syslog_facility = self._getoption('main','syslog_facility')
+        if self._getoption('main','syslog_priority') != None:
+            self.syslog_priority = self._getoption('main','syslog_priority')
         if self._getoption('main','pkgpolicy') != None:
             self.pkgpolicy = self._getoption('main','pkgpolicy')
         if self._getoption('main','assumeyes') != None:

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux