Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
check_in_logfiles.py
1.0
2015-05-10
- Nagios 2.x
- Nagios 3.x
- Nagios XI
GPL
9727
File | Description |
---|---|
check_in_logfiles.py | check_in_logfiles.py |
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
Usage check_in_logfiles.py :
Nagios plugin that searches log files for a patterns loaded from a pattern file.
Usage check_in_logfiles.py :
First argument PATTERNFILE is a text file containing lines of the form:
SEVERITY:PATTERN
Where *SEVERITY* is one of `IGNORE`, `WARNING`, `CRITICAL` and *PATTERN* is a regular expression.
Second (and later) argument LOGFILE is the path to one (or more) log files.
If a line is found that matches a *PATTERN* with *SEVERITY* `CRITICAL`, exit with CRITICAL status
If a line is found that matches a *PATTERN* with *SEVERITY* `WARNING`, exit with WARNING status
Usage check_in_logfiles.py :
First argument PATTERNFILE is a text file containing lines of the form:
SEVERITY:PATTERN
Where *SEVERITY* is one of `IGNORE`, `WARNING`, `CRITICAL` and *PATTERN* is a regular expression.
Second (and later) argument LOGFILE is the path to one (or more) log files.
If a line is found that matches a *PATTERN* with *SEVERITY* `CRITICAL`, exit with CRITICAL status
If a line is found that matches a *PATTERN* with *SEVERITY* `WARNING`, exit with WARNING status
Reviews (1)
Hi, Hope you don't mind. I modified the code a bit.
Seemed that when everything was OK, Nagios failed display data.
#!/usr/bin/env python
# Check_log_files.py
# Author: Imran Ahmed
# Description: Nagios plugin that searches log files for a patterns loaded from a pattern file.
# Usage check_in_logfiles.py :
# First argument PATTERNFILE is a text file containing lines of the form:
# SEVERITY:PATTERN
# where *SEVERITY* is one of `IGNORE`, `WARNING`, `CRITICAL` and *PATTERN* is a
# regular expression.
# Second (and later) argument LOGFILE is the path to one (or more) log files.
# if a line is found that matches a *PATTERN* with *SEVERITY* `CRITICAL`,
# exit with CRITICAL status
# if a line is found that matches a *PATTERN* with *SEVERITY* `WARNING`,
# exit with WARNING status
import sys, re
def popLists(file):
with open(file, 'r') as myPatFile:
lines = myPatFile.readlines()
critical = []
warning = []
ok = []
for line in lines:
line = line.strip()
words = line.split(":")
if (words[0] =='CRITICAL'):
critical.append(words[1])
elif (words[0] =='WARNING'):
warning.append(words[1])
elif (words[0] =='OK'):
ok.append(words[1])
else:
print "Everything is cool!"
return critical, warning, ok
def main():
argc = len(sys.argv)
if argc main()
Seemed that when everything was OK, Nagios failed display data.
#!/usr/bin/env python
# Check_log_files.py
# Author: Imran Ahmed
# Description: Nagios plugin that searches log files for a patterns loaded from a pattern file.
# Usage check_in_logfiles.py :
# First argument PATTERNFILE is a text file containing lines of the form:
# SEVERITY:PATTERN
# where *SEVERITY* is one of `IGNORE`, `WARNING`, `CRITICAL` and *PATTERN* is a
# regular expression.
# Second (and later) argument LOGFILE is the path to one (or more) log files.
# if a line is found that matches a *PATTERN* with *SEVERITY* `CRITICAL`,
# exit with CRITICAL status
# if a line is found that matches a *PATTERN* with *SEVERITY* `WARNING`,
# exit with WARNING status
import sys, re
def popLists(file):
with open(file, 'r') as myPatFile:
lines = myPatFile.readlines()
critical = []
warning = []
ok = []
for line in lines:
line = line.strip()
words = line.split(":")
if (words[0] =='CRITICAL'):
critical.append(words[1])
elif (words[0] =='WARNING'):
warning.append(words[1])
elif (words[0] =='OK'):
ok.append(words[1])
else:
print "Everything is cool!"
return critical, warning, ok
def main():
argc = len(sys.argv)
if argc main()