Beispiel #1
0
 def nagiosConfigFileRemove(self):
     """remove old nagios configuration file for this object
     """
     host = zapi.getParent(self.context)
     nagiosAdapter = IGenNagios(host)
     if nagiosAdapter is not None:
         nagiosAdapter.nagiosConfigFileOut(True, None)
Beispiel #2
0
def notifyAddedEvent(instance, event):
    """
    Node was added
    """
    #print "Superclass.notifyAddedEvent"
    nagiosAdapter = IGenNagios(event.object)
    if nagiosAdapter is not None:
        nagiosAdapter.nagiosConfigFileOut(True, event)
Beispiel #3
0
def notifyAddedEvent(instance, event):
    """
    Node was added
    """
    if objEventSupported(event.object):
        valueChanged = False
        #print "generators.nagios.notifyAddedEvent"
        nagiosAdapter = IGenNagios(event.object)
        if nagiosAdapter is not None:
            if nagiosAdapter.nagiosConfigFileOut(True, event):
                valueChanged = True
Beispiel #4
0
def notifyRemovedEvent(instance, event):
    """
    Node was removed
    """
    #print "Superclass.notifyRemovedEvent"
    print "ikName:", event.object.ikName
    print "getObjectId():", event.object.getObjectId()
    nagiosAdapter = IGenNagios(event.object)
    if nagiosAdapter is not None:
        try:
            nagiosAdapter.nagiosConfigFileRemove()
        except Exception:  # no such file at this point and/or at this moment
            pass
Beispiel #5
0
 def allConfigFilesOut(self):
     """make configuration file
     """
     self.touchLastConfigFile()
     its = zapi.getRoot(self).items()
     for (dummy_name, oobj) in its:
         if ISupernode.providedBy(oobj):
             try:
                 adapterGenNagios = IGenNagios(oobj)
                 if adapterGenNagios:
                     adapterGenNagios.nagiosConfigFileOut(True, None)
             except TypeError, errText:
                 logger.error(u"Problem in adaption of nagios config: %s" %\
                              (errText))
Beispiel #6
0
def notifyRemovedEvent(instance, event):
    """
    Node was removed
    """
    if objEventSupported(event.object):
        valueChanged = False
        #print "generators.nagios.notifyRemovedEvent"
        nagiosAdapter = IGenNagios(event.object)
        if nagiosAdapter is not None:
            try:
                if nagiosAdapter.nagiosConfigFileRemove():
                    valueChanged = True
            except Exception:  # no such file at this point and/or at this moment
                pass
Beispiel #7
0
 def nagiosConfigFileOut(self, forceOutput=False, event=None):
     """Nagios-Filegenerator
     
     will produce the nagios configuration files
     
     forceOutput: False will check for a relevant attribute change
     True will alway generate a new config file
      
     event: None or the zope event from lifecycle
     """
     host = zapi.getParent(self.context)
     nagiosAdapter = IGenNagios(host)
     if nagiosAdapter is not None:
         nagiosAdapter.nagiosConfigFileOut(True, event)
Beispiel #8
0
 def allConfigFilesOut(self, context=None):
     """make configuration file
     """
     self.touchLastConfigFile()
     uidutil = getUtility(IIntIds, context=context)
     for (dummy_name, oobj) in uidutil.items():
         if INagiosCheck.providedBy(oobj.object):
             try:
                 adapterGenNagios = IGenNagios(oobj.object)
                 if adapterGenNagios:
                     adapterGenNagios.nagiosConfigFileOut(True, None)
             except TypeError, errText:
                 logger.error(u"Problem in adaption of nagios config: %s" %\
                              (errText))
Beispiel #9
0
def notifyModifiedEvent(instance, event):
    """
    Node was modified
    """
    #print "Superclass.notifyModifiedEvent"
    allEventObjs = event.object.getAllOutEventObjs()
    utilXbar = queryUtility(IAdmUtilEventCrossbar)
    for eventObj in allEventObjs:
        try:
            utilXbar[eventObj].addOidToInpObjects(event.object.objectID)
        except KeyError:
            pass
    nagiosAdapter = IGenNagios(event.object)
    if nagiosAdapter is not None:
        nagiosAdapter.nagiosConfigFileOut(False, event)
Beispiel #10
0
    def getConfig(self):
        """make configuration file
        TODO filename or filehandle must be an argument
        """
        dtHostCfg = datetime.now(berlinTZ)
        #fpHostCfg = open(u'/opt/ikomtrol/etc/Host.cfg', 'w+')
        fpHostCfg = open(u'/opt/nagios/etc/ict_ok/Host.cfg', 'w+')
        fpHostCfg.write(u"# Host.cfg\n")
        fpHostCfg.write(u"# generated by ict-ok.org Ver. %s (%s)\n\n" %
                        (getIkVersion(), dtHostCfg))

        dtHostGroupCfg = datetime.now(berlinTZ)
        #fpHostGroupCfg = open(u'/opt/ikomtrol/etc/HostGroup.cfg', 'w+')
        fpHostGroupCfg = open(u'/opt/nagios/etc/ict_ok/HostGroup.cfg', 'w+')
        fpHostGroupCfg.write(u"# HostGroup.cfg\n")
        fpHostGroupCfg.write(u"# generated by ict-ok.org Ver. %s (%s)\n\n" %
                             (getIkVersion(), dtHostGroupCfg))
        fpHostGroupCfg.write(u"define hostgroup {\n")
        fpHostGroupCfg.write(u"    hostgroup_name IKOMtrol\n")
        fpHostGroupCfg.write(u"    alias IKOMtrol-Systeme\n")
        fpHostGroupCfg.write(u"    members ")

        dtServiceCfg = datetime.now(berlinTZ)
        #fpServiceCfg = open(u'/opt/ikomtrol/etc/Service.cfg', 'w+')
        fpServiceCfg = open(u'/opt/nagios/etc/ict_ok/Service.cfg', 'w+')
        fpServiceCfg.write(u"# Service.cfg\n")
        fpServiceCfg.write(u"# generated by ict-ok.org Ver. %s (%s)\n\n" %
                           (getIkVersion(), dtServiceCfg))

        fileDict = {
            'HostCfg': fpHostCfg,
            'HostGroupCfg': fpHostGroupCfg,
            'ServiceCfg': fpServiceCfg
        }
        #cfgFile = open('/tmp/cfgNagiosFile', 'w')
        #import pdb; pdb.set_trace()
        its = zapi.getRoot(self).items()
        for (dummy_name, oobj) in its:
            if ISupernode.providedBy(oobj):
                try:
                    adapterGenNagios = IGenNagios(oobj)
                    if adapterGenNagios:
                        adapterGenNagios.traverse4nagiosGenerator(
                            fileDict, level=1, comments=False)
                except TypeError, errText:
                    logger.error(u"Problem in adaption of nagios config: %s" %\
                                 (errText))
Beispiel #11
0
 def traverse4nagiosGeneratorBody(self, fileDict, level=0, comments=True):
     """graphviz configuration data of/in object
     """
     if comments:
         print >> fileDict['HostCfg'], \
               "%s## Body (%s,%d) - SupernodeGenNagios" % \
               ("\t" * level, self.context.ikName, level)
     its = self.context.items()
     for (dummy_name, oobj) in its:
         if ISuperclass.providedBy(oobj):
             try:
                 adapterGenNagios = IGenNagios(oobj)
                 if adapterGenNagios:
                     adapterGenNagios.traverse4nagiosGenerator(
                         fileDict, level + 1, comments)
             except TypeError:
                 logger.error(u"Problem in adaption of nagios config")
Beispiel #12
0
 def traverse4nagiosGeneratorBody(self, level=0, comments=True):
     """graphviz configuration data of/in object
     """
     if comments:
         self.write("%s## Body (%s,%d) - SupernodeGenNagios" % \
                    ("\t" * level, self.context.ikName, level))
     its = self.context.items()
     for (dummy_name, oobj) in its:
         if ISuperclass.providedBy(oobj):
             try:
                 adapterGenNagios = IGenNagios(oobj)
                 if adapterGenNagios:
                     adapterGenNagios.parentAdapter = self
                     adapterGenNagios.traverse4nagiosGenerator(
                         level + 1, comments)
             except TypeError, errText:
                 logger.error(u"Problem in nagios adaption: '%s'" % \
                              errText)
Beispiel #13
0
def notifyModifiedEvent(instance, event):
    """
    Node was modified
    """
    if objEventSupported(event.object):
        valueChanged = False
        #print "generators.nagios.notifyModifiedEvent"
        allEventObjs = event.object.getAllOutEventObjs()
        utilXbar = getUtility(IAdmUtilEventCrossbar)
        for eventObj in allEventObjs:
            try:
                utilXbar[eventObj].addOidToInpObjects(event.object.objectID)
            except KeyError:
                pass
        nagiosAdapter = IGenNagios(event.object)
        if nagiosAdapter is not None:
            if nagiosAdapter.nagiosConfigFileOut(False, event):
                valueChanged = True
            if valueChanged:
                utilNagios = getUtility(IAdmUtilGeneratorNagios)
                reloadString = u"%s reload" % utilNagios.pathInitScript
                #print "reloadString: ", reloadString
                os.system(reloadString)