Exemple #1
0
    def __init__(self,
                 sensor_type_map_table,
                 sensors_key='sensor_value',
                 sensor_type_column_name='type',
                 sensor_type_match_column='endpoint_name',
                 data_tables_dict={},
                 **kwargs):
        '''
        sensor_type_map_table (str): name of the child endpoint of this instance which provides access to the endpoint_id_map, which stores the sensor type
        sensor_type_column_name (str): name of the column to use for the return type (matched against keys in the data_tables_dict argument here)
        sensor_type_match_column (str): column against which to check for matches to the sensor name
        data_tables_dict (dict): dictionary mapping types (in the sensor_type_map_table) to child endpoints of this instance which provide access to the data_table for that type
        '''
        self.prefix = sensors_key
        kwargs.update({'keys': ['{}.#'.format(sensors_key)]})
        PostgreSQLInterface.__init__(self, **kwargs)
        Gogol.__init__(self, **kwargs)
        logger.debug('bindings are: {}'.format(self._bindings))

        self._sensor_type_map_table = sensor_type_map_table
        self._sensor_type_column_name = sensor_type_column_name
        self._sensor_type_match_column = sensor_type_match_column
        self._sensor_types = {}
        self._data_tables = data_tables_dict
        self.service = self
    def __init__(self,sensor_definitions='', **kwargs):
        '''
        sensor_definition_file (str): name of a yaml file encoding sensor metadata
        '''
        Gogol.__init__(self, **kwargs)
#self.sensor_defs=yaml.load(open(os.path.expanduser(sensor_definition_file)))
        self.sensor_defs=sensor_definitions
        self.sensor_tags=dict()
        #use the sensor_types info to populate the sensor_tags
        for sensor_name in self.sensor_defs["sensors"]:
            for sensor_type in self.sensor_defs["sensors"][sensor_name]["sensor_types"]:
                if sensor_type in self.sensor_defs["sensor_types"]:
                    if "tag_conditions" in self.sensor_defs["sensors"][sensor_name]:
                        self.sensor_defs["sensors"][sensor_name]["tag_conditions"].extend(self.sensor_defs["sensor_types"][sensor_type]["tag_conditions"])
                    else:
                        self.sensor_defs["sensors"][sensor_name]["tag_conditions"]=self.sensor_defs["sensor_types"][sensor_type]["tag_conditions"]
                else:
                    logger.info("Error, sensor_type not found")
         #use the generic reactions to populate sensor reactions
        for sensor_name in self.sensor_defs["sensors"]:
            if "reactions" in self.sensor_defs["sensors"][sensor_name]:
                self.sensor_defs["sensors"][sensor_name]["reactions"].extend(self.sensor_defs["generic_reactions"])
            else:
                self.sensor_defs["sensors"][sensor_name]["reactions"]=self.sensor_defs["generic_reactions"]
        #the message queue is what I'm about to log to info
        #it's there so when I do things like email someone or post to slack,
        #I don't senda  whole bunch of messages. I only send the queue every queue_flush_time
        self.message_queue_info=""
        self.queue_flush_time_seconds=20
        self.last_queue_flush=time()-self.queue_flush_time_seconds
Exemple #3
0
    def __init__(self,
                 input_channel,
                 output_channel,
                 check_channel,
                 payload_field='value_cal',
                 tolerance = 0.01,
                 target_value=110,
                 proportional=0.0, integral=0.0, differential=0.0,
                 maximum_out=1.0, minimum_out=1.0, delta_out_min= 0.001,
                 enable_offset_term=True,
                 minimum_elapsed_time=0,
                 **kwargs
                ):
        '''
        input_channel (str): name of the logging sensor to use as input to PID (this will override any provided values for keys)
        output_channel (str): name of the endpoint to be set() based on PID
        check_channel (str): name of the endpoint to be checked() after a set()
        input_payload_field (str): name of the field in the payload when the sensor logs (default is 'value_cal' and 'value_raw' is the only other expected value)
        target_value (float): numerical value to which the loop will try to lock the input_channel
        proportional (float): coefficient for the P term in the PID equation
        integral (float): coefficient for the I term in the PID equation
        differential (float): coefficient for the D term in the PID equation
        maximum_out (float): max value to which the output_channel may be set; if the PID equation gives a larger value this value is used instead
        delta_out_min (float): minimum value by which to change the output_channel; if the PID equation gives a smaller change, the value is left unchanged (no set is attempted)
        tolerance (float): acceptable difference between the set and get values (default: 0.01)
        '''
        kwargs.update({'keys':['sensor_value.'+input_channel]})
        Gogol.__init__(self, **kwargs)

        self._set_channel = output_channel
        self._check_channel = check_channel
        self.payload_field = payload_field
        self.tolerance = tolerance

        self.target_value = target_value

        self.Kproportional = proportional
        self.Kintegral = integral
        self.Kdifferential = differential

        self._integral= 0

        self.max_current = maximum_out
        self.min_current = minimum_out
        self.min_current_change = delta_out_min

        self.enable_offset_term = enable_offset_term
        self.minimum_elapsed_time = minimum_elapsed_time

        self._old_current = self.__get_current()
        logger.info('starting current is: {}'.format(self._old_current))
Exemple #4
0
    def __init__(self, sensor_type_map_table, data_tables_dict={}, **kwargs):
        '''
        sensor_type_map_table (str): name of the child endpoint of this instance which provides access to the endpoint_id_map, which stores the sensor type
        data_tables_dict (dict): dictionary mapping types (in the sensor_type_map_table) to child endpoints of this instance which provide access to the data_table for that type
        '''
        # listen to sensor_value alerts channel
        kwargs.update({'exchange':'alerts','keys':['sensor_value.#']})
        Gogol.__init__(self, **kwargs)
        PostgreSQLInterface.__init__(self, **kwargs)

        self._sensor_type_map_table = sensor_type_map_table
        self._sensor_types = {}
        self._data_tables = data_tables_dict
        self.service = self
Exemple #5
0
 def __init__(self,
              sensors,
              targets,
              routing_key_base='sensor_value.',
              **kwargs):
     '''
     key_base (str): alerts exchange base, used to form complete names of alerts to bind
     sensors (list): list of endpoint and alarms to configure
     '''
     self.start_time = datetime.datetime.utcnow()
     self.configure_monitors(sensors)
     self.targets = targets
     self.routing_key = routing_key_base
     kwargs.update(
         {'keys': [routing_key_base + x for x in self.monitors.keys()]})
     Gogol.__init__(self, **kwargs)
Exemple #6
0
 def __init__(self,
              disk_space_alert = 0.8,
              disk_space_critical = 0.9,
              time_between_warnings = 60,
              actions_conditions = None,
              **kwargs):
     '''
     disk_space_alert: used space threshold above which the Disk Monitor will start to send alerts
     '''
     # listen to status_message alerts channel
     kwargs.update({'keys':['disk_status.#.#']})
     Gogol.__init__(self, **kwargs)
     self.history = {}
     self._time_between_warnings = time_between_warnings
     self._disk_space_alert = disk_space_alert
     self._disk_space_critical = disk_space_critical
     self._action_when_critical = actions_conditions
    def __init__(self,
                 prime_speakers = None,
                 speaking_time = 60,
                 time_between_warnings=600,
                 number_sentence_per_speaking_time = 30,
                 slack_channel='p8_alerts',
                 **kwargs):
        '''
        prime_speakers: define which users are allowed to speak as much as they want and we are not allowed to stop them from it
        speaking_time: duration while it is allowed for a service to say things before being muted
        number_sentence_per_speaking_time: number of messages allowed during speaking_time before being muted
        time_between_warnings: time between sending warnings
        '''
        # listen to status_message alerts channel
        #kwargs.update({'exchange':'alerts','keys':['status_message.#.#']})
        kwargs.update({'keys':['status_message.#.#']})
        Gogol.__init__(self, **kwargs)

        # get the authentification file and look for a slack field
        this_home = os.path.expanduser('~')
        slack = {}
        config_file = json.loads(open(this_home+'/.project8_authentications.json').read())
        if 'slack' in config_file:
            slack = config_file['slack']
        else:
            raise dripline.core.exceptions.DriplineValueError('Warning! unable to find slack credentials in <~/.project8_authentications.json>')

        # grab the token used for authentification to slack
        token = None
        if 'dripline' in slack:
            token = slack['dripline']
        elif 'token' in slack:
            token = slack['token']
        if token:
            self.slackclient = slackclient.SlackClient(token)
        else:
            self.slackclient = None
            raise dripline.core.exceptions.DriplineValueError('Warning! unable to find slack token in <~/.project8_authentications.json>')

        # Keep track of the frequency of emission of the services
        self.history = {}
        self._prime_speakers = prime_speakers
        self._speaking_time = speaking_time
        self._time_between_warnings = time_between_warnings
        self._nspst = number_sentence_per_speaking_time
        self.slack_channel = '#'+slack_channel
Exemple #8
0
 def add_endpoint(self, endpoint):
     # establish Spimescape add_endpoint as a starter
     Gogol.add_endpoint(self, endpoint)
     # forcing PostgreSQLInterface add_endpoint usage
     PostgreSQLInterface.add_endpoint(self, endpoint)