Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
Added a log'd warning if the Nagios serv-perf-data file grows too lar…
Browse files Browse the repository at this point in the history
…ge (and thus slows down processing)
  • Loading branch information
Adam Bishop committed Apr 14, 2010
1 parent 72dae58 commit 528e948
Showing 1 changed file with 51 additions and 4 deletions.
55 changes: 51 additions & 4 deletions monitoring/nagios/nimbus_nagios_data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
import ConfigParser
from xml.dom.pulldom import parseString, parse, START_ELEMENT
import sys
from nimbus_nagios_logger import Logger
#from nimbus_nagios_logger import Logger
import logging
import libxml2
import libxslt
import time
Expand All @@ -39,11 +40,13 @@

RET_CRITICAL = -1

LARGE_FILE_SIZE = 1024 # kBytes, so 1 MB

# Must specify the full path as Nagios doesn't setup a complete environment
# when it calls this script
REMOVE_DUP_XSL = "/usr/local/nagios/libexec/removeAllDup.xsl"
MERGE_NODES_XSL = "/usr/local/nagios/libexec/merge.xsl"
ATTRIBUTE_STRIP_XSL = "/usr/local/nagios/libexec/attribStripper.xsl"
REMOVE_DUP_XSL = "/usr/local/nagios/libexec/nimbus_nagios_rem_dup_nodes.xsl"
MERGE_NODES_XSL = "/usr/local/nagios/libexec/nimbus_nagios_merge_nodes.xsl"
ATTRIBUTE_STRIP_XSL = "/usr/local/nagios/libexec/nimbus_nagios_rem_attrib.xsl"
XSD = "cloud.xsd"

CONF_FILE = "/usr/local/nagios/libexec/monitoring_config.cfg"
Expand Down Expand Up @@ -81,6 +84,43 @@ def loadConfig(logger):
logger.error("Configuration file not found in Nagios Plug-ins directory")
sys.exit(RET_CRITICAL)


class Logger:
""" A class to encapsulate useful logging features and setup
"""
def __init__(self, name, errorLogFile):

self.logger = logging.getLogger(name)

self.logger.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s : %(name)s : %(levelname)s : %(message)s')

nagiosObservableHndlr = logging.StreamHandler(sys.stdout)
nagiosObservableHndlr.setLevel(logging.INFO)
nagiosObservableHndlr.setFormatter(formatter)

fileOutputHndlr = logging.FileHandler(errorLogFile)
fileOutputHndlr.setFormatter(formatter)
fileOutputHndlr.setLevel(logging.DEBUG)

self.logger.addHandler(fileOutputHndlr)
self.logger.addHandler(nagiosObservableHndlr)

def warning(self, msg):
self.logger.warning(msg)

def info(self, msg):
self.logger.info(msg)

def error(self, msg):
self.logger.error(msg)

def debug(self, msg):
self.logger.debug(msg)



class NagiosXMLAggregator:

def __init__(self):
Expand All @@ -99,6 +139,13 @@ def aggregateServiceDataToXML(self):
# These tags will NOT appear in any XML and are only used internally in this file
retXML.write("<WRAPPER>")
if (os.path.exists(ConfigMapping[PERFORMANCE_DATA_LOC])):

# getsize returns the size of the file in bytes
curFileSize = os.path.getsize(ConfigMapping[PERFORMANCE_DATA_LOC])/(1024)
#print curFileSize
if(curFileSize > LARGE_FILE_SIZE):
self.logger.warning("The service performance data file: "+ConfigMapping[PERFORMANCE_DATA_LOC]+" has grown larger than "+str(LARGE_FILE_SIZE)+" kB!")
self.logger.warning("This will slow down the data processing script considerably")
try:
fileHandle = open(ConfigMapping[PERFORMANCE_DATA_LOC],"r")

Expand Down

0 comments on commit 528e948

Please sign in to comment.