[checkmk-commits] Check_MK Git: check_mk: logwatch agents/plugins now with ok pattern support

git version control git at mathias-kettner.de
Mon Nov 5 14:37:24 CET 2012


Module: check_mk
Branch: master
Commit: 421edb7274f6bc6d1f4be490acdbb6055140cadf
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=421edb7274f6bc6d1f4be490acdbb6055140cadf

Author: Andreas Boesl <ab at mathias-kettner.de>
Date:   Mon Nov  5 14:37:13 2012 +0100

logwatch agents/plugins now with ok pattern support

---

 ChangeLog                         |    1 +
 agents/plugins/mk_logwatch        |   18 +++++++++---------
 agents/windows/check_mk_agent.cc  |    2 +-
 agents/windows/check_mk_agent.exe |  Bin 109568 -> 109568 bytes
 agents/windows/install_agent.exe  |  Bin 129941 -> 129945 bytes
 checks/logwatch                   |   10 +++++-----
 web/htdocs/logwatch.css           |    5 +++++
 web/htdocs/logwatch.py            |    8 ++++++++
 8 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b260bba..b8ce60d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -61,6 +61,7 @@
            progress dialogs (e.g. bulk inventory mode)
     * FIX: Fixed editing of icon_image rules
     * Added support of locked hosts and folders ( created by CMDB )
+    * Logwatch: logwatch agents/plugins now with ok pattern support 
 
     Checks & Agents:
     * New check mssql_counters.locks: Monitors locking related information of
diff --git a/agents/plugins/mk_logwatch b/agents/plugins/mk_logwatch
index 2910ab6..821fab5 100755
--- a/agents/plugins/mk_logwatch
+++ b/agents/plugins/mk_logwatch
@@ -74,7 +74,7 @@ def parse_pattern(line):
         compiled = re.compile(pattern)
     except:
         raise(Exception("Invalid regular expression in line '%s'" % line))
-    if level not in [ 'C', 'W', 'I' ]:
+    if level not in [ 'C', 'W', 'I', 'O' ]:
         raise(Exception("Invalid pattern line '%s'" % line))
     return (level, compiled)
 
@@ -177,7 +177,7 @@ def process_logfile(logfile, patterns):
     # now seek to offset where interesting data begins
     os.lseek(fl, offset, 0) # os.SEEK_SET not available in Python 2.4
     f = os.fdopen(fl)
-    worst = 0
+    worst = -1
     outputtxt = ""
     lines_parsed = 0
     start_time = time.time()
@@ -206,17 +206,17 @@ def process_logfile(logfile, patterns):
         for lev, pattern in patterns:
             if pattern.search(line[:-1]):
                 level = lev
-                levelint = {'C': 2, 'W': 1, 'I': 0, '.': 0}[lev]
+                levelint = {'C': 2, 'W': 1, 'O': 0, 'I': -1, '.': -1}[lev]
                 worst = max(levelint, worst)
                 break
-        color = {'C': tty_red, 'W': tty_yellow, 'I': tty_blue, '.': ''}[level]
+        color = {'C': tty_red, 'W': tty_yellow, 'O': tty_green, 'I': tty_blue, '.': ''}[level]
         outputtxt += "%s%s %s%s\n" % (color, level, line[:-1], tty_normal)
 
     new_offset = os.lseek(fl, 0, 1) # os.SEEK_CUR not available in Python 2.4
     status[logfile] = new_offset, inode
 
-    # output all lines if at least one warning or error has been found
-    if worst > 0:
+    # output all lines if at least one warning, error or ok has been found
+    if worst > -1:
         sys.stdout.write(outputtxt)
         sys.stdout.flush()
 
@@ -251,10 +251,10 @@ for filenames, patterns in config:
             elif key == 'maxtime':
                 opt_maxtime = float(value)
             elif key == 'overflow':
-                if value not in [ 'C', 'I', 'W' ]:
-                    raise Exception("Invalid value %s for overflow. Allowed are C, I and W" % value)
+                if value not in [ 'C', 'I', 'W', 'O' ]:
+                    raise Exception("Invalid value %s for overflow. Allowed are C, I, O and W" % value)
                 opt_overflow = value
-                opt_overflow_level = {'C':2, 'W':1, 'I':0}[value]
+                opt_overflow_level = {'C':2, 'W':1, 'O':0, 'I':0}[value]
             elif key == 'regex':
                 opt_regex = re.compile(value)
             elif key == 'iregex':
diff --git a/agents/windows/check_mk_agent.cc b/agents/windows/check_mk_agent.cc
index aacb292..ff0b467 100755
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -1622,7 +1622,7 @@ bool process_textfile(FILE *file, logwatch_textfile* textfile, SOCKET &out, bool
             }
         }
         if (write_output && strlen(line) > 0)
-            output(out, "%c %s\n", state == 'O' ? 'I' : state, line);
+            output(out, "%c %s\n", state, line);
     }
 
     return false;
diff --git a/agents/windows/check_mk_agent.exe b/agents/windows/check_mk_agent.exe
index d2bf124..c137d77 100755
Binary files a/agents/windows/check_mk_agent.exe and b/agents/windows/check_mk_agent.exe differ
diff --git a/agents/windows/install_agent.exe b/agents/windows/install_agent.exe
index c372d48..5f5f52d 100755
Binary files a/agents/windows/install_agent.exe and b/agents/windows/install_agent.exe differ
diff --git a/checks/logwatch b/checks/logwatch
index 9100e2b..57e1c9a 100644
--- a/checks/logwatch
+++ b/checks/logwatch
@@ -88,13 +88,15 @@ def logwatch_state(state):
         return "OK"
 
 def logwatch_level_name(level):
-    if   level == 'W': return 'WARN'
+    if   level == 'I': return 'OK'
+    elif level == 'O': return 'OK'
+    elif level == 'W': return 'WARN'
     elif level == 'C': return 'CRIT'
-    elif level == 'I': return 'OK'
     else: return 'IGN'
 
 def logwatch_level_worst(worst, level):
     if   level == 'I': return max(worst, 0)
+    elif level == 'O': return max(worst, 0)
     elif level == 'W': return max(worst, 1)
     elif level == 'C': return max(worst, 2)
     else: return worst
@@ -116,9 +118,7 @@ def logwatch_precompile(hostname, item, _unused):
             # only modify the levels taken from the defined rules.
             # FIXME: Oneday we should clean it up. Maybe via hint in migration nodes or
             # some mor inteligent valuespec, ...
-            if pattern[0] == 'O': # Fix "OK" declaration
-                level = 'I'
-            elif pattern[0] == 'I': # Fix "IGNORE" declaration
+            if pattern[0] == 'I': # Fix "IGNORE" declaration
                 level = 'S'
             else:
                 level = pattern[0]
diff --git a/web/htdocs/logwatch.css b/web/htdocs/logwatch.css
index 49df5a4..41f9ded 100644
--- a/web/htdocs/logwatch.css
+++ b/web/htdocs/logwatch.css
@@ -89,6 +89,11 @@ Boston, MA 02110-1301 USA.
     border-bottom: 1px solid #c00;
 }
 
+#logwatch .OK {
+    background-color: #0b3;
+    border-bottom: 1px solid #0c0;
+}
+
 #logwatch td.WARN, td.CRIT, td.OK {
     width: 5em;
     text-align: center;
diff --git a/web/htdocs/logwatch.py b/web/htdocs/logwatch.py
index 0747285..9c6a518 100644
--- a/web/htdocs/logwatch.py
+++ b/web/htdocs/logwatch.py
@@ -33,11 +33,13 @@ stylesheets = [ 'pages', 'status', 'logwatch' ]
 def level_name(level):
     if   level == 'W': return 'WARN'
     elif level == 'C': return 'CRIT'
+    elif level == 'O': return 'OK'
     else: return 'OK'
 
 def level_state(level):
     if   level == 'W': return 1
     elif level == 'C': return 2
+    elif level == 'O': return 0
     else: return 0
 
 #   .----------------------------------------------------------------------.
@@ -301,6 +303,8 @@ def parse_file(host, file, hidecontext = False):
                     log['level'] = 2
                 elif level == 'WARN':
                     log['level'] = 1
+                elif level == 'OK':
+                    log['level'] = 0
                 else:
                     log['level'] = 0
 
@@ -321,6 +325,10 @@ def parse_file(host, file, hidecontext = False):
                 elif line[0] == 'C':
                     line_level = 2
                     line_class = 'CRIT'
+                
+                elif line[0] == 'O': 
+                    line_level = 0 
+                    line_class = 'OK'
 
                 elif not hidecontext:
                     line_level = 0



More information about the checkmk-commits mailing list