Example #1
0
class Pack(Item):  # pragma: no cover, this class looks no more used - see #551
    """
    Class to manage a Pack
    A Pack contain multiple configuration files (like all checks for os 'FreeBSD')
    """
    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):
        """
        Get the name of the pack

        :return: the pack name string or 'UnnamedPack'
        :rtype: str
        """
        try:
            return self.pack_name
        except AttributeError:
            return 'UnnamedPack'
Example #2
0
class ArbiterLink(SatelliteLink):
    """
    Class to manage the link to Arbiter daemon.
    With it, a master arbiter can communicate with  a spare Arbiter daemon
    """
    my_type = 'arbiter'
    properties = SatelliteLink.properties.copy()
    properties.update({
        'type':
        StringProp(default=u'arbiter', fill_brok=['full_status'],
                   to_send=True),
        'arbiter_name':
        StringProp(default='', fill_brok=['full_status']),
        'host_name':
        StringProp(default=socket.gethostname(), to_send=True),
        'port':
        IntegerProp(default=7770, to_send=True),
        'last_master_speak':
        FloatProp(default=0.0)
    })

    def is_me(self):  # pragma: no cover, seems not to be used anywhere
        """Check if parameter name if same than name of this object

        TODO: is it useful?

        :return: true if parameter name if same than this name
        :rtype: bool
        """
        logger.info(
            "And arbiter is launched with the hostname:%s "
            "from an arbiter point of view of addr:%s", self.host_name,
            socket.getfqdn())
        return self.host_name == socket.getfqdn(
        ) or self.host_name == socket.gethostname()

    def do_not_run(self):
        """Check if satellite running or not
        If not, try to run

        :return: true if satellite not running
        :rtype: bool
        """
        logger.debug("[%s] do_not_run", self.name)

        try:
            self.con.get('_do_not_run')
            return True
        except HTTPClientConnectionException as exp:  # pragma: no cover, simple protection
            self.add_failed_check_attempt("Connection error when "
                                          "sending do not run: %s" % str(exp))
            self.set_dead()
        except HTTPClientTimeoutException as exp:  # pragma: no cover, simple protection
            self.add_failed_check_attempt("Connection timeout when "
                                          "sending do not run: %s" % str(exp))
        except HTTPClientException as exp:
            self.add_failed_check_attempt("Error when "
                                          "sending do not run: %s" % str(exp))

        return False
Example #3
0
class Hostescalation(Item):
    """Hostescalation class is used to implement notification escalation for hosts

    TODO: Why this class does not inherit from alignak.objects.Escalation.
          Maybe we can merge it
    """
    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(),
    })
Example #4
0
class Module(Item):
    """
    Class to manage a module
    """
    _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_alias': StringProp(),
        'python_name': StringProp(),
        'modules': ListProp(default=[''], split_on_coma=True),
    })

    macros = {}

    # For debugging purpose only (nice name)
    def get_name(self):
        """
        Get name of module

        :return: Name of module
        :rtype: str
        """
        return self.module_alias

    def __repr__(self):
        return '<module module=%s alias=%s />' % (self.python_name,
                                                  self.module_alias)

    __str__ = __repr__
Example #5
0
class Businessimpactmodulation(Item):
    """Businessimpactmodulation class is simply a modulation of the business impact value
    (of a Host/Service) during a modulation period.
    """
    my_type = 'businessimpactmodulation'

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

    def __init__(self, params=None, parsing=True):
        super(Businessimpactmodulation, self).__init__(params, parsing=parsing)

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

    def get_name(self):
        """Accessor to business_impact_modulation_name attribute

        :return: business impact modulation name
        :rtype: str
        """
        if hasattr(self, 'business_impact_modulation_name'):
            return self.business_impact_modulation_name
        return 'Unnamed'
Example #6
0
class BrokerLink(SatelliteLink):
    """
    Class to manage the broker information
    """
    my_type = 'broker'
    properties = SatelliteLink.properties.copy()
    properties.update({
        'type':
        StringProp(default=u'broker', fill_brok=['full_status'], to_send=True),
        'broker_name':
        StringProp(default='', fill_brok=['full_status']),
        'port':
        IntegerProp(default=7772, fill_brok=['full_status'], to_send=True),
        'initialized':
        BoolProp(default=False, fill_brok=['full_status'], to_send=True),
    })

    def prepare_for_conf(self):
        """Initialize the pushed configuration dictionary
        with the inner properties that are to be propagated to the satellite link.

        :return: None
        """
        super(BrokerLink, self).prepare_for_conf()

        self.cfg.update({
            'satellites': {
                'receivers': {},
                'pollers': {},
                'reactionners': {}
            }
        })
Example #7
0
class PollerLink(SatelliteLink):
    """
    Class to manage the link between Arbiter and Poller. With this, an arbiter
    can communicate with a poller
    """
    my_type = 'poller'
    # To_send: send or not to satellite conf
    properties = SatelliteLink.properties.copy()
    properties.update({
        'type':
        StringProp(default=u'poller', fill_brok=['full_status'], to_send=True),
        'poller_name':
        StringProp(default='', fill_brok=['full_status']),
        'port':
        IntegerProp(default=7771, 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),
        # 'worker_polling_interval':
        #     IntegerProp(default=1, to_send=True),
        'poller_tags':
        ListProp(default=['None'], to_send=True),
    })
Example #8
0
class Pack(Item):
    """
    Class to manage a Pack
    A Pack contain multiple configuration files (like all checks for os 'FreeBSD')
    """
    _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):
        """
        Get the name of the pack

        :return: the pack name string or 'UnnamedPack'
        :rtype: str
        """
        try:
            return self.pack_name
        except AttributeError:
            return 'UnnamedPack'
Example #9
0
class Comment(AlignakObject):
    """Comment class implements comments for monitoring purpose.
    It contains data like author, type etc..
    """

    my_type = 'comment'
    properties = {
        'entry_time':   IntegerProp(),
        'author':       StringProp(default='(Alignak)'),
        'comment':      StringProp(default='Automatic Comment'),
        'comment_type': IntegerProp(),
        'entry_type':   IntegerProp(),
        'source':       IntegerProp(),
        'expires':      BoolProp(),
        'ref':  StringProp(default=''),
    }

    def __init__(self, params, parsing=True):
        """Adds a comment to a particular service.

        :param ref: reference object (host / service)
        :type ref: alignak.object.schedulingitem.SchedulingItem
        :param author: Author of this comment
        :type author: str
        :param comment: text comment itself
        :type comment: str
        :param comment_type: comment type ::

                            * 1 <=> HOST_COMMENT
                            * 2 <=> SERVICE_COMMENT

        :type comment_type: int
        :param entry_type: type of entry linked to this comment ::

                          * 1 <=> USER_COMMENT
                          * 2 <=>DOWNTIME_COMMENT
                          * 3 <=>FLAPPING_COMMENT
                          * 4 <=>ACKNOWLEDGEMENT_COMMENT

        :type entry_type: int
        :param source: source of this comment ::

                      * 0 <=> COMMENTSOURCE_INTERNAL
                      * 1 <=> COMMENTSOURCE_EXTERNAL

        :type source: int
        :param expires: comment expires or not
        :type expires: bool
        :return: None
        """
        super(Comment, self).__init__(params, parsing)
        if not hasattr(self, 'entry_time'):
            self.entry_time = int(time.time())
        self.fill_default()

    def __str__(self):
        return "Comment id=%s %s" % (self.uuid, self.comment)
Example #10
0
class SchedulerLink(SatelliteLink):
    """
    Class to manage the scheduler information
    """
    _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']),
    })

    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 run_external_commands(self, commands):
        """
        Run external commands

        :param commands:
        :type commands:
        :return: False, None
        :rtype: bool | None
        TODO: need recode this fonction because return types are too many
        """
        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
Example #11
0
class SchedulerLink(SatelliteLink):
    """
    Class to manage the scheduler information
    """

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

    properties = SatelliteLink.properties.copy()
    properties.update({
        'type':
        StringProp(default=u'scheduler',
                   fill_brok=['full_status'],
                   to_send=True),
        'scheduler_name':
        StringProp(default='', fill_brok=['full_status']),
        'port':
        IntegerProp(default=7768, fill_brok=['full_status'], to_send=True),
        'weight':
        IntegerProp(default=1, fill_brok=['full_status']),
        'skip_initial_broks':
        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),
    })

    running_properties = SatelliteLink.running_properties.copy()
    running_properties.update({
        # 'conf':
        #     StringProp(default=None),
        # 'cfg':
        #     DictProp(default={}),
        'need_conf': StringProp(default=True),
        'external_commands': StringProp(default=[]),
    })

    def get_override_configuration(self):
        """
        Some parameters can give as 'overridden parameters' like use_timezone
        so they will be mixed (in the scheduler) with the standard conf sent by the arbiter

        :return: dictionary of properties
        :rtype: dict
        """
        res = {}
        properties = self.__class__.properties
        for prop, entry in list(properties.items()):
            if entry.override:
                res[prop] = getattr(self, prop)
        return res
Example #12
0
class Module(Item):
    """
    Class to manage a module
    """
    my_type = 'module'

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

    macros = {}

    # For debugging purpose only (nice name)
    def get_name(self):
        """
        Get name of module

        :return: Name of module
        :rtype: str
        """
        return self.module_alias

    def get_types(self):
        """
        Get name of module

        :return: Name of module
        :rtype: str
        """
        return self.module_types

    def is_a_module(self, module_type):
        """
        Is the module of the required type?

        :param module_type: module type to check
        :type: str
        :return: True / False
        """
        return module_type in self.module_types

    def __repr__(self):
        return '<module module=%s alias=%s />' % (self.python_name, self.module_alias)

    __str__ = __repr__
Example #13
0
class ReceiverLink(SatelliteLink):
    """
    Class to manage the receiver information
    """
    my_type = 'receiver'
    properties = SatelliteLink.properties.copy()
    properties.update({
        'type':
        StringProp(default='receiver', fill_brok=['full_status'],
                   to_send=True),
        'receiver_name':
        StringProp(default='', fill_brok=['full_status'], to_send=True),
        'port':
        IntegerProp(default=7772, fill_brok=['full_status'], to_send=True),
    })
Example #14
0
class Poller(Satellite):
    """Poller class. Referenced as "app" in most Interface

    """
    do_checks = True  # I do checks
    do_actions = False  # but no actions
    my_type = 'poller'

    properties = Satellite.properties.copy()
    properties.update({
        'daemon_type': StringProp(default='poller'),
        'pidfile': PathProp(default='pollerd.pid'),
        'port': IntegerProp(default=7771),
        'local_log': PathProp(default='pollerd.log'),
    })

    def __init__(self,
                 config_file,
                 is_daemon,
                 do_replace,
                 debug,
                 debug_file,
                 port=None,
                 local_log=None,
                 daemon_name=None):
        self.daemon_name = 'poller'
        if daemon_name:
            self.daemon_name = daemon_name

        super(Poller,
              self).__init__(self.daemon_name, config_file, is_daemon,
                             do_replace, debug, debug_file, port, local_log)
Example #15
0
class EventHandler(Action):
    """Notification class, inherits from action class. Used to execute action
    when a host or a service is in a bad state

    """

    # AutoSlots create the __slots__ with properties and
    # running_properties names
    __metaclass__ = AutoSlots

    my_type = 'eventhandler'

    properties = Action.properties.copy()
    properties.update({
        'is_a': StringProp(default=u'eventhandler'),
        'is_snapshot': BoolProp(default=False),
    })

    def __init__(self, params=None, parsing=False):
        super(EventHandler, self).__init__(params, parsing=parsing)

        self.fill_default()

        # An event handler mus be launched as soon as possible
        self.t_to_go = time.time()

    def __str__(self):  # pragma: no cover
        return "Event Handler %s, item: %s, status: %s command: %s" \
               % (self.uuid, self.ref, self.status, self.command)

    def get_return_from(self, e_handler):
        """Setter of the following attributes::

        * exit_status
        * output
        * long_output
        * check_time
        * execution_time
        * perf_data

        :param e_handler: event handler to get data from
        :type e_handler: alignak.eventhandler.EventHandler
        :return: None
        """
        for prop in [
                'exit_status', 'output', 'long_output', 'check_time',
                'execution_time', 'perf_data'
        ]:
            setattr(self, prop, getattr(e_handler, prop))

    def get_outputs(self, out, max_plugins_output_length):
        """Setter of output attribute

        :param out: new output
        :type out: str
        :param max_plugins_output_length: not used
        :type max_plugins_output_length: int
        :return: None
        """
        self.output = out
Example #16
0
class Reactionner(Satellite):
    """
    This class is an application that launches actions for the schedulers
    Actions can be:
       Notifications
       Event handlers

    When running the Reactionner will :
      Respond to pings from Arbiter
      Listen for new configurations from Arbiter

    The configuration consists of a list of Schedulers for which
    the Reactionner will launch actions for.
    """
    do_checks = False  # I do not do checks
    do_actions = True
    my_type = 'reactionner'

    properties = Satellite.properties.copy()
    properties.update({
        'type':
            StringProp(default='reactionner'),
        'port':
            IntegerProp(default=7769)
    })

    def __init__(self, **kwargs):
        """Reactionner daemon initialisation

        :param kwargs: command line arguments
        """
        super(Reactionner, self).__init__(kwargs.get('daemon_name',
                                                     'Default-reactionner'), **kwargs)
Example #17
0
class ReactionnerLink(SatelliteLink):
    """
    Class to manage the reactionner information
    """
    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 register_to_my_realm(
            self):  # pragma: no cover, seems not to be used anywhere
        """
        Add this reactionner to the realm

        :return: None
        """
        self.realm.reactionners.append(self)
Example #18
0
class PollerLink(SatelliteLink):
    """
    Class to manage the link between Arbiter and Poller. With it, arbiter
    can see if a poller is alive, and can send it new configuration
    """
    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),
        'poller_tags':
        ListProp(default=['None'], to_send=True),
    })

    def register_to_my_realm(
            self):  # pragma: no cover, seems not to be used anywhere
        """
        Add this relation to the realm

        :return: None
        """
        self.realm.pollers.append(self)
Example #19
0
class ReceiverLink(SatelliteLink):
    """
    Class to manage the receiver information
    """
    _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),
    })

    def register_to_my_realm(self):
        """
        Add this reactionner to the realm

        :return: None
        """
        self.realm.receivers.append(self)

    def push_host_names(self, sched_id, hnames):
        """
        Send host names to receiver

        :param sched_id: id of the scheduler
        :type sched_id: int
        :param hnames: list of host names
        :type hnames: list
        :return: None
        """
        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))
Example #20
0
class Resultmodulation(Item):
    """Resultmodulation class is simply a modulation of a check result exit code
    during a modulation_period.

    """
    _id = 1  # zero is always special in database, so we do not take risk here
    my_type = 'resultmodulation'

    properties = Item.properties.copy()
    properties.update({
        'resultmodulation_name': StringProp(),
        'exit_codes_match': IntListProp(default=[]),
        'exit_code_modulation': IntegerProp(default=None),
        'modulation_period': StringProp(default=None),
    })

    def get_name(self):
        """Accessor to resultmodulation_name attribute

        :return: result modulation name
        :rtype: str
        """
        return self.resultmodulation_name

    def module_return(self, return_code):
        """Module the exit code if necessary ::

        * modulation_period is legit
        * exit_code_modulation
        * return_code in exit_codes_match

        :param return_code: actual code returned by the check
        :type return_code: int
        :return: return_code modulated if necessary (exit_code_modulation)
        :rtype: int
        """
        # 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
Example #21
0
class Hostdependency(Item):
    """Hostdependency class is a simple implementation of host dependency as
    defined in a monitoring context (dependency period, notification_failure_criteria ..)

    """
    _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='')
    })

    def get_name(self):
        """Get name based on dependent_host_name and host_name attributes
        Each attribute is substituted by 'unknown' if attribute does not exist

        :return: dependent_host_name/host_name
        :rtype: str
        """
        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
Example #22
0
class Serviceescalation(Item):
    """Serviceescalation class is used to implement notification escalation for services

    TODO: Why this class does not inherit from alignak.objects.Escalation.
          Maybe we can merge it
    """
    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=['w', 'x', 'c', 'r'], split_on_comma=True),
        'contacts':
        ListProp(default=[], merging='join', split_on_comma=True),
        'contact_groups':
        ListProp(default=[], merging='join', split_on_comma=True),
        'first_notification_time':
        IntegerProp(),
        'last_notification_time':
        IntegerProp(),
    })

    def __init__(self, params=None, parsing=True):
        if params is None:
            params = {}

        for prop in ['escalation_options']:
            if prop in params:
                params[prop] = [p.replace('u', 'x') for p in params[prop]]
        super(Serviceescalation, self).__init__(params, parsing=parsing)
Example #23
0
class Hostescalation(Item):
    """Hostescalation class is used to implement notification escalation for hosts

    TODO: Why this class does not inherit from alignak.objects.Escalation.
          Maybe we can merge it
    """
    _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(),
    })

    def get_name(self):
        """Get escalation name

        :return: name
        :rtype: str
        TODO: Remove this function
        """
        return ''
Example #24
0
class Businessimpactmodulation(Item):
    """Businessimpactmodulation class is simply a modulation of the business impact value
    (of a Host/Service) during a modulation period.
    """
    _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=''),
    })

    def get_name(self):
        """Accessor to business_impact_modulation_name attribute

        :return: business impact modulation name
        :rtype: str
        """
        return self.business_impact_modulation_name
Example #25
0
class Servicedependency(Item):
    """Servicedependency class is a simple implementation of service dependency as
    defined in a monitoring context (dependency period, notification_failure_criteria ..)

    """
    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=False),
        'execution_failure_criteria':
        ListProp(default=['n'], split_on_comma=True),
        'notification_failure_criteria':
        ListProp(default=['n'], split_on_comma=True),
        'dependency_period':
        StringProp(default=''),
        'explode_hostgroup':
        BoolProp(default=False)
    })

    def get_name(self):
        """Get name based on 4 class attributes
        Each attribute is substituted by '' if attribute does not exist

        :return: dependent_host_name/dependent_service_description..host_name/service_description
        :rtype: str
        TODO: Clean this function (use format for string)
        """
        return getattr(self, 'dependent_host_name', '') + '/'\
            + getattr(self, 'dependent_service_description', '') \
            + '..' + getattr(self, 'host_name', '') + '/' \
            + getattr(self, 'service_description', '')
Example #26
0
class HostExtInfo(GenericExtInfo):
    """HostExtInfo class is made to handle some parameters of SchedulingItem::

    * notes
    * notes_url
    * icon_image
    * icon_image_alt

    TODO: Is this class really necessary?

    """
    # AutoSlots create the __slots__ with properties and
    # running_properties names
    __metaclass__ = AutoSlots

    my_type = 'hostextinfo'

    properties = Item.properties.copy()
    properties.update({
        'host_name': StringProp(),
        'notes': StringProp(default=u''),
        'notes_url': StringProp(default=u''),
        'icon_image': StringProp(default=u''),
        'icon_image_alt': StringProp(default=u''),
        'vrml_image': StringProp(default=u''),
        'statusmap_image': StringProp(default=u''),

        # No slots for this 2 because begin property by a number seems bad
        # it's stupid!
        '2d_coords': StringProp(default=u'', no_slots=True),
        '3d_coords': StringProp(default=u'', no_slots=True),
    })

    # Hosts macros and prop that give the information
    # the prop can be callable or not
    macros = {
        'HOSTNAME': 'host_name',
        'HOSTNOTESURL': 'notes_url',
        'HOSTNOTES': 'notes',
    }
Example #27
0
class Reactionner(Satellite):
    """
    This class is an application that launches actions for the schedulers
    Actions can be:
       Notifications
       Event handlers

    When running the Reactionner will :
      Respond to pings from Arbiter
      Listen for new configurations from Arbiter

    The configuration consists of a list of Schedulers for which
    the Reactionner will launch actions for.
    """
    do_checks = False  # I do not do checks
    do_actions = True
    my_type = 'reactionner'

    properties = Satellite.properties.copy()
    properties.update({
        'daemon_type': StringProp(default='reactionner'),
        'pidfile': PathProp(default='reactionnerd.pid'),
        'port': IntegerProp(default=7769),
        'local_log': PathProp(default='reactionnerd.log'),
    })

    def __init__(self,
                 config_file,
                 is_daemon,
                 do_replace,
                 debug,
                 debug_file,
                 port=None,
                 local_log=None,
                 daemon_name=None):
        self.daemon_name = 'reactionner'
        if daemon_name:
            self.daemon_name = daemon_name

        super(Reactionner,
              self).__init__(self.daemon_name, config_file, is_daemon,
                             do_replace, debug, debug_file, port, local_log)
Example #28
0
class BrokerLink(SatelliteLink):
    """
    Class to manage the broker information
    """
    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']),
    })

    def register_to_my_realm(
            self):  # pragma: no cover, seems not to be used anywhere
        """
        Add this broker to the realm

        :return: None
        """
        self.realm.brokers.append(self)
Example #29
0
class ServiceExtInfo(GenericExtInfo):
    """ServiceExtInfo class is made to handle some parameters of SchedulingItem::

    * notes
    * notes_url
    * icon_image
    * icon_image_alt

    TODO: Is this class really necessary?

    """
    # AutoSlots create the __slots__ with properties and
    # running_properties names
    __metaclass__ = AutoSlots

    my_type = 'serviceextinfo'

    # properties defined by configuration
    # *required: is required in conf
    # *default: default value if no set in conf
    # *pythonize: function to call when transforming string to python object
    # *fill_brok: if set, send to broker. there are two categories:
    #   full_status for initial and update status, check_result for check results
    # *no_slots: do not take this property for __slots__
    #  Only for the initial call
    # conf_send_preparation: if set, will pass the property to this function. It's used to "flatten"
    #  some dangerous properties like realms that are too 'linked' to be send like that.
    # brok_transformation: if set, will call the function with the value of the property
    #  the major times it will be to flatten the data (like realm_name instead of the realm object).
    properties = Item.properties.copy()
    properties.update({
        'host_name': StringProp(),
        'service_description': StringProp(),
        'notes': StringProp(default=''),
        'notes_url': StringProp(default=''),
        'icon_image': StringProp(default=''),
        'icon_image_alt': StringProp(default=''),
    })

    # Hosts macros and prop that give the information
    # the prop can be callable or not
    macros = {
        'SERVICEDESC': 'service_description',
        'SERVICEACTIONURL': 'action_url',
        'SERVICENOTESURL': 'notes_url',
        'SERVICENOTES': 'notes'
    }
Example #30
0
class Poller(Satellite):
    """Poller class. Referenced as "app" in most Interface

    """
    do_checks = True  # I do checks
    do_actions = False  # but no actions
    my_type = 'poller'

    properties = Satellite.properties.copy()
    properties.update({
        'type': StringProp(default='poller'),
        'port': IntegerProp(default=7771)
    })

    def __init__(self, **kwargs):
        """Poller daemon initialisation

        :param kwargs: command line arguments
        """
        super(Poller,
              self).__init__(kwargs.get('daemon_name', 'Default-poller'),
                             **kwargs)