Exemplo n.º 1
0
class Hostdependency(Item):
    id = 0

#F is dep of D
#host_name                      Host B
#       service_description             Service D
#       dependent_host_name             Host C
#       dependent_service_description   Service F
#       execution_failure_criteria      o
#       notification_failure_criteria   w,u
#       inherits_parent         1
#       dependency_period       24x7

    properties = {
        'dependent_host_name':           StringProp(),
        'dependent_hostgroup_name':      StringProp(default=''),
        'host_name':                     StringProp(),
        'hostgroup_name':                StringProp(default=''),
        'inherits_parent':               BoolProp(default='0'),
        'execution_failure_criteria':    ListProp(default='n'),
        'notification_failure_criteria': ListProp(default='n'),
        'dependency_period':             StringProp(default='')
    }
    
    running_properties = {
        'configuration_errors': ListProp(default=[]),
        }

    # Give a nice name output, for debbuging purpose
    # (debugging happens more often than expected...)
    def get_name(self):
        return self.dependent_host_name+'/'+self.host_name
Exemplo n.º 2
0
class Hostescalation(Item):
    id = 1  # zero is always special in database, so we do not take risk here
    my_type = 'hostescalation'

    properties = Item.properties.copy()
    properties.update({
        'host_name':
        StringProp(),
        'hostgroup_name':
        StringProp(),
        'first_notification':
        IntegerProp(),
        'last_notification':
        IntegerProp(),
        'notification_interval':
        IntegerProp(default=30),  # like Nagios value
        'escalation_period':
        StringProp(default=''),
        'escalation_options':
        ListProp(default=['d', 'u', 'r', 'w', 'c']),
        'contacts':
        StringProp(),
        'contact_groups':
        StringProp(),
        'first_notification_time':
        IntegerProp(),
        'last_notification_time':
        IntegerProp(),
    })

    # For debugging purpose only (nice name)
    def get_name(self):
        return ''
Exemplo n.º 3
0
class Contactgroup(Itemgroup):
    id = 1
    my_type = 'contactgroup'

    properties = Itemgroup.properties.copy()
    properties.update({
        'id':                   IntegerProp(default=0, fill_brok=['full_status']),
        'contactgroup_name':    StringProp(fill_brok=['full_status']),
        'alias':                StringProp(fill_brok=['full_status']),
    })

    macros = {
        'CONTACTGROUPALIAS': 'alias',
        'CONTACTGROUPMEMBERS': 'get_members'
    }

    def get_contacts(self):
        return getattr(self, 'members', '')

    def get_name(self):
        return getattr(self, 'contactgroup_name', 'UNNAMED-CONTACTGROUP')

    def get_contactgroup_members(self):
        if self.has('contactgroup_members'):
            return self.contactgroup_members.split(',')
        else:
            return []

    # We fillfull properties with template ones if need
    # Because hostgroup we call may not have it's members
    # we call get_hosts_by_explosion on it
    def get_contacts_by_explosion(self, contactgroups):
        # First we tag the hg so it will not be explode
        # if a son of it already call it
        self.already_explode = True

        # Now the recursive part
        # rec_tag is set to False every CG we explode
        # so if True here, it must be a loop in HG
        # calls... not GOOD!
        if self.rec_tag:
            logger.error("[contactgroup::%s] got a loop in contactgroup definition", self.get_name())
            if self.has('members'):
                return self.members
            else:
                return ''
        # Ok, not a loop, we tag it and continue
        self.rec_tag = True

        cg_mbrs = self.get_contactgroup_members()
        for cg_mbr in cg_mbrs:
            cg = contactgroups.find_by_name(cg_mbr.strip())
            if cg is not None:
                value = cg.get_contacts_by_explosion(contactgroups)
                if value is not None:
                    self.add_string_member(value)
        if self.has('members'):
            return self.members
        else:
            return ''
Exemplo n.º 4
0
class ReactionnerLink(SatelliteLink):
    """Please Add a Docstring to describe the class here"""

    id = 0
    my_type = 'reactionner'
    properties = SatelliteLink.properties.copy()
    properties.update({
        'reactionner_name':
        StringProp(fill_brok=['full_status'], to_send=True),
        'port':
        IntegerProp(default=7769, fill_brok=['full_status']),
        'min_workers':
        IntegerProp(default=1, fill_brok=['full_status'], to_send=True),
        'max_workers':
        IntegerProp(default=30, fill_brok=['full_status'], to_send=True),
        'processes_by_worker':
        IntegerProp(default=256, fill_brok=['full_status'], to_send=True),
        'max_q_size':
        IntegerProp(default=0, fill_brok=['full_status'], to_send=True),
        'q_factor':
        IntegerProp(default=0, fill_brok=['full_status'], to_send=True),
        'results_batch':
        IntegerProp(default=0, fill_brok=['full_status'], to_send=True),
        'reactionner_tags':
        ListProp(default=['None'], to_send=True),
        'harakiri_threshold':
        StringProp(default=None, fill_brok=['full_status'], to_send=True),
    })

    def get_name(self):
        return self.reactionner_name

    def register_to_my_realm(self):
        self.realm.reactionners.append(self)
Exemplo n.º 5
0
class Trigger(Item):
    id = 1  # zero is always special in database, so we do not take risk here
    my_type = 'trigger'

    properties = Item.properties.copy()
    properties.update({
        'trigger_name':
        StringProp(fill_brok=['full_status']),
        'code_src':
        StringProp(default='', fill_brok=['full_status']),
    })

    running_properties = Item.running_properties.copy()
    running_properties.update({
        'code_bin':
        StringProp(default=None),
        'trigger_broker_raise_enabled':
        BoolProp(default=False)
    })

    # For debugging purpose only (nice name)
    def get_name(self):
        try:
            return self.trigger_name
        except AttributeError:
            return 'UnnamedTrigger'

    def compile(self):
        self.code_bin = compile(self.code_src, "<irc>", "exec")

    # ctx is the object we are evaluating the code. In the code
    # it will be "self".
    def eval(myself, ctx):
        self = ctx

        # Ok we can declare for this trigger call our functions
        for (n, f) in trigger_functions.iteritems():
            locals()[n] = f

        code = myself.code_bin  # Comment? => compile(myself.code_bin, "<irc>", "exec")
        try:
            exec code in dict(locals())
        except Exception as err:
            set_value(self, "UNKNOWN: Trigger error: %s" % err, "", 3)
            logger.error('%s Trigger %s failed: %s ; %s' %
                         (self.host_name, myself.trigger_name, err,
                          traceback.format_exc()))

    def __getstate__(self):
        return {
            'trigger_name': self.trigger_name,
            'code_src': self.code_src,
            'trigger_broker_raise_enabled': self.trigger_broker_raise_enabled
        }

    def __setstate__(self, d):
        self.trigger_name = d['trigger_name']
        self.code_src = d['code_src']
        self.trigger_broker_raise_enabled = d['trigger_broker_raise_enabled']
Exemplo n.º 6
0
class Realm(Itemgroup):
    id = 1  # zero is always a little bit special... like in database
    my_type = 'realm'

    properties = Itemgroup.properties.copy()
    properties.update({
        'id':            IntegerProp(default=0, fill_brok=['full_status']),
        'realm_name':    StringProp(fill_brok=['full_status']),
        'realm_members': StringProp(default=''), # No status_broker_name because it put hosts, not host_name
        'higher_realms': StringProp(default=''),
        'default':       BoolProp(default='0'),
        'broker_complete_links':       BoolProp(default='0'),
        #'alias': {'required':  True, 'fill_brok': ['full_status']},
        #'notes': {'required': False, 'default':'', 'fill_brok': ['full_status']},
        #'notes_url': {'required': False, 'default':'', 'fill_brok': ['full_status']},
        #'action_url': {'required': False, 'default':'', 'fill_brok': ['full_status']},
    })

    running_properties = Item.running_properties.copy()
    running_properties.update({
            'serialized_confs': StringProp(default={}),
        })

    macros = {
        'REALMNAME': 'realm_name',
        'REALMMEMBERS': 'members',
    }


    def get_name(self):
        return self.realm_name


    def get_realms(self):
        return self.realm_members


    def add_string_member(self, member):
        self.realm_members += ',' + member


    def get_realm_members(self):
        if self.has('realm_members'):
            return [r.strip() for r in self.realm_members.split(',')]
        else:
            return []

    # Use to make python properties
    # TODO: change itemgroup function pythonize?
    def pythonize(self):
        cls = self.__class__
        for prop, tab in cls.properties.items():
            try:
                old_val = getattr(self, prop)
                new_val = tab.pythonize(old_val)
                #print "Changing ", old_val, "by", new_val
                setattr(self, prop, new_val)
            except AttributeError, exp:
                pass  # Will be catch at the is_correct moment
Exemplo n.º 7
0
class ArbiterLink(SatelliteLink):
    id = 0
    my_type = 'arbiter'
    properties = SatelliteLink.properties.copy()
    properties.update({
        'arbiter_name':    StringProp(),
        'host_name':       StringProp(default=socket.gethostname()),
        'port':            IntegerProp(default=7770),
    })

    def get_name(self):
        return self.arbiter_name

    def get_config(self):
        return self.con.get('get_config')

    # Check is required when prop are set:
    # contacts OR contactgroups is need
    def is_correct(self):
        state = True
        cls = self.__class__

        for prop, entry in cls.properties.items():
            if not hasattr(self, prop) and entry.required:
                # This should raise an error afterwards?
                # Log the issue
                logger.warning("%s arbiterlink is missing %s property", self.get_name(), prop)
                self.debug("%s arbiterlink is missing %s property" % (self.get_name(), prop))
                state = False  # Bad boy...
        return state


    # Look for ourself as an arbiter. If we search for a specific arbiter name, go forit
    # If not look be our fqdn name, or if not, our hostname
    def is_me(self, lookup_name):
        logger.info("And arbiter is launched with the hostname:%s from an arbiter point of view of addr:%s", self.host_name, socket.getfqdn())
        if lookup_name:
            return lookup_name == self.get_name()
        else:
            return self.host_name == socket.getfqdn() or self.host_name == socket.gethostname()


    def give_satellite_cfg(self):
        return {'port': self.port, 'address': self.address, 'name': self.arbiter_name, 'use_ssl':self.use_ssl, 'hard_ssl_name_check':self.hard_ssl_name_check}


    def do_not_run(self):
        if self.con is None:
            self.create_connection()
        try:
            self.con.get('do_not_run')
            return True
        except HTTPExceptions, exp:
            self.con = None
            return False
Exemplo n.º 8
0
class MacroModulation(Item):
    id = 1  # zero is always special in database, so we do not take risk here
    my_type = 'macromodulation'

    properties = Item.properties.copy()
    properties.update({
        'macromodulation_name':
        StringProp(fill_brok=['full_status']),
        'modulation_period':
        StringProp(brok_transformation=to_name_if_possible,
                   fill_brok=['full_status']),
    })

    running_properties = Item.running_properties.copy()

    _special_properties = ('modulation_period', )

    macros = {}

    # For debugging purpose only (nice name)
    def get_name(self):
        return self.macromodulation_name

    # Will say if we are active or not
    def is_active(self):
        now = int(time.time())
        if not self.modulation_period or self.modulation_period.is_time_valid(
                now):
            return True
        return False

    # Should have all properties, or a void macro_period
    def is_correct(self):
        state = True
        cls = self.__class__

        # Raised all previously saw errors like unknown commands or timeperiods
        if self.configuration_errors != []:
            state = False
            for err in self.configuration_errors:
                logger.error("[item::%s] %s" % (self.get_name(), err))

        for prop, entry in cls.properties.items():
            if prop not in cls._special_properties:
                if not hasattr(self, prop) and entry.required:
                    logger.warning(
                        "[macromodulation::%s] %s property not set" %
                        (self.get_name(), prop))
                    state = False  # Bad boy...

        # Ok just put None as modulation_period, means 24x7
        if not hasattr(self, 'modulation_period'):
            self.modulation_period = None

        return state
Exemplo n.º 9
0
class Resultmodulation(Item):
    id = 1#0 is always special in database, so we do not take risk here
    my_type = 'resultmodulation'

    properties = {
        'resultmodulation_name': StringProp(),
        'exit_codes_match':      ListProp  (default=''),
        'exit_code_modulation':  StringProp(default=None),
        'modulation_period':     StringProp(default=None),
    }
    
    running_properties = {
        'configuration_errors': ListProp(default=[]),
        }
    macros = {}


    #For debugging purpose only (nice name)
    def get_name(self):
        return self.resultmodulation_name


    def clean(self):
        pass


    #Make the return code modulation if need
    def module_return(self, return_code):
        #Only if in modulation_period of modulation_period == None
        if self.modulation_period is None or self.modulation_period.is_time_valid(time.time()):
            #Try to change the exit code only if a new one is defined
            if self.exit_code_modulation is not None:
                #First with the exit_code_match
                if return_code in self.exit_codes_match:
                    return_code = self.exit_code_modulation

        return return_code


    #We override the pythonize because we have special cases that we do not want
    #to be do at running
    def pythonize(self):
        #First apply Item pythonize
        super(self.__class__, self).pythonize()

        #Then very special cases
        # Intify the exit_codes_match, and make list
        self.exit_codes_match = [ int(ec) for ec in getattr(self, 'exit_codes_match', []) ]

        if hasattr(self, 'exit_code_modulation'):
            self.exit_code_modulation = int(self.exit_code_modulation)
        else:
            self.exit_code_modulation = None
class Businessimpactmodulation(Item):
    id = 1  # zero is always special in database, so we do not take risk here
    my_type = 'businessimpactmodulation'

    properties = Item.properties.copy()
    properties.update({'business_impact_modulation_name': StringProp(),
                       'business_impact':                 IntegerProp(),
                       'modulation_period':               StringProp(default=''),
                       })

    # For debugging purpose only (nice name)
    def get_name(self):
        return self.business_impact_modulation_name
Exemplo n.º 11
0
class ReceiverLink(SatelliteLink):
    """Please Add a Docstring to describe the class here"""

    id = 0
    my_type = 'receiver'
    properties = SatelliteLink.properties.copy()
    properties.update({
        'receiver_name':
        StringProp(fill_brok=['full_status'], to_send=True),
        'port':
        IntegerProp(default=7772, fill_brok=['full_status']),
        'manage_sub_realms':
        BoolProp(default=True, fill_brok=['full_status']),
        'manage_arbiters':
        BoolProp(default=False, fill_brok=['full_status'], to_send=True),
        'direct_routing':
        BoolProp(default=False, fill_brok=['full_status'], to_send=True),
        'accept_passive_unknown_check_results':
        BoolProp(default=False, fill_brok=['full_status'], to_send=True),
        'harakiri_threshold':
        StringProp(default=None, fill_brok=['full_status'], to_send=True),
    })

    def get_name(self):
        return self.receiver_name

    def register_to_my_realm(self):
        self.realm.receivers.append(self)

    def push_host_names(self, sched_id, hnames):
        try:
            if self.con is None:
                self.create_connection()
            logger.info(" (%s)", self.uri)

            # If the connection failed to initialize, bail out
            if self.con is None:
                self.add_failed_check_attempt()
                return

            # r = self.con.push_host_names(sched_id, hnames)
            self.con.get('ping')
            self.con.post('push_host_names', {
                'sched_id': sched_id,
                'hnames': hnames
            },
                          wait='long')
        except HTTPExceptions, exp:
            self.add_failed_check_attempt(reason=str(exp))
Exemplo n.º 12
0
class ArbiterLink(SatelliteLink):
    id = 0
    my_type = 'arbiter'
    properties = SatelliteLink.properties.copy()
    properties.update({
        'arbiter_name': StringProp(),
        'host_name': StringProp(default=socket.gethostname()),
        'port': IntegerProp(default='7770'),
    })

    def get_name(self):
        return self.arbiter_name

    #Check is required prop are set:
    #contacts OR contactgroups is need
    def is_correct(self):
        state = True  #guilty or not? :)
        cls = self.__class__

        for prop, entry in cls.properties.items():
            if not hasattr(self, prop) and entry.required:
                print self.get_name(), " : I do not have", prop
                state = False  #Bad boy...
        return state

    def is_me(self):
        print "Hostname:%s, gethostname:%s" % (self.host_name,
                                               socket.gethostname())
        return self.host_name == socket.gethostname()

    def give_satellite_cfg(self):
        return {
            'port': self.port,
            'address': self.address,
            'name': self.arbiter_name
        }

    def do_not_run(self):
        if self.con is None:
            self.create_connexion()
        try:
            self.con.do_not_run()
            return True
        except Pyro.errors.URIError, exp:
            self.con = None
            return False
        except Pyro.errors.ProtocolError, exp:
            self.con = None
            return False
Exemplo n.º 13
0
class ReactionnerLink(SatelliteLink):
    """Please Add a Docstring to describe the class here"""

    id = 0
    my_type = 'reactionner'
    properties = SatelliteLink.properties.copy()
    properties.update({
        'reactionner_name':
        StringProp(fill_brok=['full_status'], to_send=True),
        'port':
        IntegerProp(default='7769', fill_brok=['full_status']),
        'min_workers':
        IntegerProp(default='1', fill_brok=['full_status'], to_send=True),
        'max_workers':
        IntegerProp(default='30', fill_brok=['full_status'], to_send=True),
        'processes_by_worker':
        IntegerProp(default='256', fill_brok=['full_status'], to_send=True),
        'reactionner_tags':
        ListProp(default='None', to_send=True),
    })

    def get_name(self):
        return self.reactionner_name

    def register_to_my_realm(self):
        self.realm.reactionners.append(self)
Exemplo n.º 14
0
class Module(Item):
    id = 1  # zero is always special in database, so we do not take risk here
    my_type = 'module'

    properties = Item.properties.copy()
    properties.update({
        'module_name': StringProp(),
        'module_type': StringProp(),
        'modules': ListProp(default=''),
    })

    macros = {}

    # For debugging purpose only (nice name)
    def get_name(self):
        return self.module_name
Exemplo n.º 15
0
class Pack(Item):
    id = 1  # zero is always special in database, so we do not take risk here
    my_type = 'pack'

    properties = Item.properties.copy()
    properties.update({'pack_name': StringProp(fill_brok=['full_status'])})

    running_properties = Item.running_properties.copy()
    running_properties.update({'macros': StringProp(default={})})

    # For debugging purpose only (nice name)
    def get_name(self):
        try:
            return self.pack_name
        except AttributeError:
            return 'UnnamedPack'
Exemplo n.º 16
0
class Module(Item):
    id = 1  #0 is always special in database, so we do not take risk here
    my_type = 'module'

    properties = {
        'module_name': StringProp(),
        'module_type': StringProp(),
    }

    running_properties = {}

    macros = {}

    #For debugging purpose only (nice name)
    def get_name(self):
        return self.module_name
Exemplo n.º 17
0
class PollerLink(SatelliteLink):
    """This class is the link between Arbiter and Poller. With it, arbiter
    can see if a poller is alive, and can send it new configuration

    """

    id = 0
    my_type = 'poller'
    # To_send: send or not to satellite conf
    properties = SatelliteLink.properties.copy()
    properties.update({
        'poller_name':
        StringProp(fill_brok=['full_status'], to_send=True),
        'port':
        IntegerProp(default=7771, fill_brok=['full_status']),
        'passive':
        BoolProp(default='0', fill_brok=['full_status'], to_send=True),
        'min_workers':
        IntegerProp(default='0', fill_brok=['full_status'], to_send=True),
        'max_workers':
        IntegerProp(default='30', fill_brok=['full_status'], to_send=True),
        'processes_by_worker':
        IntegerProp(default='256', fill_brok=['full_status'], to_send=True),
        'poller_tags':
        ListProp(default='None', to_send=True),
    })

    def get_name(self):
        return self.poller_name

    def register_to_my_realm(self):
        self.realm.pollers.append(self)
Exemplo n.º 18
0
class SchedulerLink(SatelliteLink):
    """Please Add a Docstring to describe the class here"""

    id = 0

    # Ok we lie a little here because we are a mere link in fact
    my_type = 'scheduler'

    properties = SatelliteLink.properties.copy()
    properties.update({
        'scheduler_name':
        StringProp(fill_brok=['full_status']),
        'port':
        IntegerProp(default=7768, fill_brok=['full_status']),
        'weight':
        IntegerProp(default=1, fill_brok=['full_status']),
        'skip_initial_broks':
        BoolProp(default=False, fill_brok=['full_status']),
        'accept_passive_unknown_check_results':
        BoolProp(default=False, fill_brok=['full_status']),
        'harakiri_threshold':
        StringProp(default=None, fill_brok=['full_status'], to_send=True),
    })

    running_properties = SatelliteLink.running_properties.copy()
    running_properties.update({
        'conf': StringProp(default=None),
        'need_conf': StringProp(default=True),
        'external_commands': StringProp(default=[]),
        'push_flavor': IntegerProp(default=0),
    })

    def get_name(self):
        return self.scheduler_name

    def run_external_commands(self, commands):
        if self.con is None:
            self.create_connection()
        if not self.alive:
            return None
        logger.debug("[SchedulerLink] Sending %d commands", len(commands))
        try:
            self.con.post('run_external_commands', {'cmds': commands})
        except HTTPExceptions, exp:
            self.con = None
            logger.debug(exp)
            return False
Exemplo n.º 19
0
class ArbiterLink(SatelliteLink):
    id = 0
    my_type = 'arbiter'
    properties = SatelliteLink.properties.copy()
    properties.update({
        'arbiter_name': StringProp(),
        'host_name': StringProp(default=socket.gethostname()),
        'port': IntegerProp(default=7770),
    })

    def get_name(self):
        return self.arbiter_name

    def get_config(self):
        return self.con.get('get_config')

    # Look for ourself as an arbiter. If we search for a specific arbiter name, go forit
    # If not look be our fqdn name, or if not, our hostname
    def is_me(self, lookup_name):
        logger.info(
            "And arbiter is launched with the hostname:%s "
            "from an arbiter point of view of addr:%s", self.host_name,
            socket.getfqdn())
        if lookup_name:
            return lookup_name == self.get_name()
        else:
            return self.host_name == socket.getfqdn(
            ) or self.host_name == socket.gethostname()

    def give_satellite_cfg(self):
        return {
            'port': self.port,
            'address': self.address,
            'name': self.arbiter_name,
            'use_ssl': self.use_ssl,
            'hard_ssl_name_check': self.hard_ssl_name_check
        }

    def do_not_run(self):
        if self.con is None:
            self.create_connection()
        try:
            self.con.get('do_not_run')
            return True
        except HTTPExceptions, exp:
            self.con = None
            return False
Exemplo n.º 20
0
class Hostdependency(Item):
    id = 0
    my_type = 'hostdependency'

    # F is dep of D
    # host_name                      Host B
    #       service_description             Service D
    #       dependent_host_name             Host C
    #       dependent_service_description   Service F
    #       execution_failure_criteria      o
    #       notification_failure_criteria   w,u
    #       inherits_parent         1
    #       dependency_period       24x7

    properties = Item.properties.copy()
    properties.update({
        'dependent_host_name':
        StringProp(),
        'dependent_hostgroup_name':
        StringProp(default=''),
        'host_name':
        StringProp(),
        'hostgroup_name':
        StringProp(default=''),
        'inherits_parent':
        BoolProp(default=False),
        'execution_failure_criteria':
        ListProp(default=['n'], split_on_coma=True),
        'notification_failure_criteria':
        ListProp(default=['n'], split_on_coma=True),
        'dependency_period':
        StringProp(default='')
    })

    # Give a nice name output, for debugging purpose
    # (debugging happens more often than expected...)
    def get_name(self):
        dependent_host_name = 'unknown'
        if getattr(self, 'dependent_host_name', None):
            dependent_host_name = getattr(getattr(self, 'dependent_host_name'),
                                          'host_name', 'unknown')
        host_name = 'unknown'
        if getattr(self, 'host_name', None):
            host_name = getattr(getattr(self, 'host_name'), 'host_name',
                                'unknown')
        return dependent_host_name + '/' + host_name
Exemplo n.º 21
0
class Discoveryrun(Item):
    id = 1  #0 is always special in database, so we do not take risk here
    my_type = 'discoveryrun'

    properties = {
        'discoveryrun_name': StringProp(),
        'discoveryrun_command': StringProp(),
    }

    running_properties = {
        'current_launch': StringProp(default=None),
        'configuration_errors': ListProp(default=[]),
    }

    macros = {}

    # Output name
    def get_name(self):
        return self.discoveryrun_name

    # Get an eventhandler object and launch it
    def launch(self):
        m = MacroResolver()
        data = []
        cmd = m.resolve_command(self.discoveryrun_command, data)
        self.current_launch = EventHandler(cmd, timeout=300)
        self.current_launch.execute()

    def check_finished(self):
        max_output = 10**9
        #print "Max output", max_output
        self.current_launch.check_finished(max_output)

    # Look if the current launch is done or not
    def is_finished(self):
        if self.current_launch == None:
            return True
        if self.current_launch.status in ('done', 'timeout'):
            return True
        return False

    # we use an EventHandler object, so we have output with a single line
    # and longoutput with the rest. We just need to return all
    def get_output(self):
        return '\n'.join(
            [self.current_launch.output, self.current_launch.long_output])
Exemplo n.º 22
0
class Servicedependency(Item):
    id = 0
    my_type = "servicedependency"

    # F is dep of D
    # host_name                      Host B
    #       service_description             Service D
    #       dependent_host_name             Host C
    #       dependent_service_description   Service F
    #       execution_failure_criteria      o
    #       notification_failure_criteria   w,u
    #       inherits_parent         1
    #       dependency_period       24x7

    properties = Item.properties.copy()
    properties.update({
        'dependent_host_name':           StringProp(),
        'dependent_hostgroup_name':      StringProp(default=''),
        'dependent_service_description': StringProp(),
        'host_name':                     StringProp(),
        'hostgroup_name':                StringProp(default=''),
        'service_description':           StringProp(),
        'inherits_parent':               BoolProp(default='0'),
        'execution_failure_criteria':    ListProp(default='n'),
        'notification_failure_criteria': ListProp(default='n'),
        'dependency_period':             StringProp(default=''),
        'explode_hostgroup':             BoolProp(default='0')
    })

    # Give a nice name output, for debbuging purpose
    # (Yes, debbuging CAN happen...)
    def get_name(self):
        return getattr(self, 'dependent_host_name', '') + '/' + getattr(self, 'dependent_service_description', '') + '..' + getattr(self, 'host_name', '') + '/' + getattr(self, 'service_description', '')
Exemplo n.º 23
0
class SchedulerLink(SatelliteLink):
    """Please Add a Docstring to describe the class here"""

    id = 0

    # Ok we lie a little here because we are a mere link in fact
    my_type = 'scheduler'

    properties = SatelliteLink.properties.copy()
    properties.update({
        'scheduler_name':
        StringProp(fill_brok=['full_status']),
        'port':
        IntegerProp(default='7768', fill_brok=['full_status']),
        'weight':
        IntegerProp(default='1', fill_brok=['full_status']),
        'skip_initial_broks':
        BoolProp(default='0', fill_brok=['full_status']),
    })

    running_properties = SatelliteLink.running_properties.copy()
    running_properties.update({
        'conf': StringProp(default=None),
        'need_conf': StringProp(default=True),
        'external_commands': StringProp(default=[]),
        'push_flavor': IntegerProp(default=0),
    })

    def get_name(self):
        return self.scheduler_name

    def run_external_commands(self, commands):
        if self.con is None:
            self.create_connection()
        if not self.alive:
            return None
        logger.debug("[SchedulerLink] Sending %d commands" % len(commands))
        try:
            self.con.run_external_commands(commands)
        except Pyro.errors.URIError, exp:
            self.con = None
            return False
        except Pyro.errors.ProtocolError, exp:
            self.con = None
            return False
Exemplo n.º 24
0
class Trigger(Item):
    id = 1  # zero is always special in database, so we do not take risk here
    my_type = 'trigger'

    properties = Item.properties.copy()
    properties.update({
        'trigger_name':
        StringProp(fill_brok=['full_status']),
        'code_src':
        StringProp(default='', fill_brok=['full_status'])
    })

    running_properties = Item.running_properties.copy()
    running_properties.update({'code_bin': StringProp(default=None)})

    # For debugging purpose only (nice name)
    def get_name(self):
        try:
            return self.trigger_name
        except AttributeError:
            return 'UnnamedTrigger'

    def compile(self):
        self.code_bin = compile(self.code_src, "<irc>", "exec")

    # ctx is the object we are evaluating the code. In the code
    # it will be "self".
    def eval(myself, ctx):
        self = ctx

        # Ok we can declare for this trigger call our functions
        for (n, f) in trigger_functions.iteritems():
            locals()[n] = f

        code = myself.code_bin  # Comment? => compile(myself.code_bin, "<irc>", "exec")
        exec code in dict(locals())

    def __getstate__(self):
        return {'trigger_name': self.trigger_name, 'code_src': self.code_src}

    def __setstate__(self, d):
        self.trigger_name = d['trigger_name']
        self.code_src = d['code_src']
Exemplo n.º 25
0
class Module(Item):
    id = 1  # zero is always special in database, so we do not take risk here
    my_type = 'module'

    properties = Item.properties.copy()
    properties.update({
        'module_name': StringProp(),
        'module_type': StringProp(),
        'modules': ListProp(default=[''], split_on_coma=True),
    })

    macros = {}

    # For debugging purpose only (nice name)
    def get_name(self):
        return self.module_name

    def __repr__(self):
        return '<module name=%s />' % self.get_name()
Exemplo n.º 26
0
class BrokerLink(SatelliteLink):
    """TODO: Add some comment about this class for the doc"""
    id = 0
    my_type = 'broker'
    properties = SatelliteLink.properties.copy()
    properties.update({
        'broker_name':
        StringProp(fill_brok=['full_status'], to_send=True),
        'port':
        IntegerProp(default=7772, fill_brok=['full_status']),
        'broks_batch':
        IntegerProp(default=0, fill_brok=['full_status'], to_send=True),
        'harakiri_threshold':
        StringProp(default=None, fill_brok=['full_status'], to_send=True),
    })

    def get_name(self):
        return self.broker_name

    def register_to_my_realm(self):
        self.realm.brokers.append(self)
Exemplo n.º 27
0
class Serviceescalation(Item):
    id = 1  # zero is always special in database, so we do not take risk here
    my_type = 'serviceescalation'

    properties = Item.properties.copy()
    properties.update({
        'host_name':             StringProp(),
        'hostgroup_name':        StringProp(),
        'service_description':   StringProp(),
        'first_notification':    IntegerProp(),
        'last_notification':     IntegerProp(),
        'notification_interval': IntegerProp(default=30),  # like Nagios value
        'escalation_period':     StringProp(default=''),
        'escalation_options':    ListProp(default=['d', 'u', 'r', 'w', 'c'], split_on_coma=True),
        'contacts':              StringProp(),
        'contact_groups':        StringProp(),
        'first_notification_time': IntegerProp(),
        'last_notification_time': IntegerProp(),
    })

    def get_newid(self):
        cls = self.__class__
        value = uuid.uuid1().hex
        cls.id += 1
        return value

    # For debugging purpose only (nice name)
    def get_name(self):
        return ''
Exemplo n.º 28
0
class SchedulerLink(SatelliteLink):
    id = 0

    #Ok we lie a little here because we are a mere link in fact
    my_type = 'scheduler'

    properties = SatelliteLink.properties.copy()
    properties.update({
        'scheduler_name':   StringProp(fill_brok=['full_status']),
        'port':             IntegerProp(default='7768', fill_brok=['full_status']),
        'weight':           IntegerProp(default='1', fill_brok=['full_status']),
    })
    
    running_properties = SatelliteLink.running_properties.copy() 
    running_properties.update({
        'conf':      StringProp(default=None),
        'need_conf': StringProp(default=True),
    })


    def get_name(self):
        return self.scheduler_name


    def run_external_command(self, command):
        if self.con is None:
            self.create_connexion()
        if not self.alive:
            return None
        print "Send command", command
        try:
            self.con.run_external_command(command)
        except Pyro.errors.URIError , exp:
            self.con = None
            return False
        except Pyro.errors.ProtocolError , exp:
            self.con = None
            return False
Exemplo n.º 29
0
class PollerLink(SatelliteLink):
    """This class is the link between Arbiter and Poller. With it, arbiter
    can see if a poller is alive, and can send it new configuration

    """

    id = 0
    my_type = 'poller'
    # To_send: send or not to satellite conf
    properties = SatelliteLink.properties.copy()
    properties.update({
        'poller_name':
        StringProp(fill_brok=['full_status'], to_send=True),
        'port':
        IntegerProp(default=7771, fill_brok=['full_status']),
        'min_workers':
        IntegerProp(default=0, fill_brok=['full_status'], to_send=True),
        'max_workers':
        IntegerProp(default=30, fill_brok=['full_status'], to_send=True),
        'processes_by_worker':
        IntegerProp(default=256, fill_brok=['full_status'], to_send=True),
        'max_q_size':
        IntegerProp(default=0, fill_brok=['full_status'], to_send=True),
        'q_factor':
        IntegerProp(default=0, fill_brok=['full_status'], to_send=True),
        'results_batch':
        IntegerProp(default=0, fill_brok=['full_status'], to_send=True),
        'poller_tags':
        ListProp(default=['None'], to_send=True),
        'harakiri_threshold':
        StringProp(default=None, fill_brok=['full_status'], to_send=True),
    })

    def get_name(self):
        return getattr(self, 'poller_name', 'UNNAMED-POLLER')

    def register_to_my_realm(self):
        self.realm.pollers.append(self)
Exemplo n.º 30
0
class Hostescalation(Item):
    id = 1  #0 is always special in database, so we do not take risk here
    my_type = 'hostescalation'

    properties = {
        'host_name': StringProp(),
        'hostgroup_name': StringProp(),
        'first_notification': IntegerProp(),
        'last_notification': IntegerProp(),
        'notification_interval': IntegerProp(),
        'escalation_period': StringProp(default=''),
        'escalation_options': ListProp(default='d,u,r,w,c'),
        'contacts': StringProp(),
        'contact_groups': StringProp(),
    }

    running_properties = {}

    macros = {}

    #For debugging purpose only (nice name)
    def get_name(self):
        return ''