Example #1
0
 def nextTuple(self):
     now = time.time()
     if self.lastchecked == 0:
         self.lastchecked = now
     elif now - self.lastchecked >= 60: 
         self.lastchecked = now
         id = "periodic_%s" % str(uuid4())
         body = json.dumps({'message_id': CHECK_METRIC_ALARM_MSG_ID})
         message = "Periodic monitoring message sent [%s] %s"
         LOG.debug(message % (id, body))
         emit([None, body], id=id)
     else:
         time.sleep(1)
Example #2
0
 def nextTuple(self):
     now = self.get_now()
     
     if self.lastchecked != now:
         self.lastchecked = now
         
         ready_to_evaluate = self.check_counter >= self.warmup_period
         msg_id = "periodic_%s" % str(uuid4())
         body = json.dumps({'message_id': CHECK_METRIC_ALARM_MSG_ID,
                            'ready_to_evaluate': ready_to_evaluate})
         emit([None, body], id=msg_id)
         LOG.info("Periodic monitoring message sent[%s]%s. counter: %d",
                  msg_id, body, self.check_counter)
         
     else:
         time.sleep(1)
Example #3
0
    def nextTuple(self):
        if not self.worker_pool.waiting():
            self.worker_pool.spawn_n(self.read_from_queue)

        count = 0
        while (not self.queue.empty() and count < self.MAX_WORKERS):
            count += 1
            frame, body = self.queue.get()
            msg_body = json.loads(body)
            msg_id = msg_body['message_id']
            msg_req_id = ":".join(
                (msg_body['message_uuid'], msg_body['context']['request_id'],
                 str(frame.delivery_tag)))
            message = "Start processing message in the queue - [%s:%s] %s"
            LOG.info(message, msg_id, msg_req_id, body)
            emit([body], id=msg_req_id)
Example #4
0
 def nextTuple(self):
     if not self.worker_pool.waiting():
         self.worker_pool.spawn_n(self.read_from_queue)
     
     count = 0
     while (not self.queue.empty() and count < self.MAX_WORKERS):
         count += 1
         frame, body = self.queue.get()
         msg_body = json.loads(body)
         msg_id = msg_body['message_id']
         msg_req_id = ":".join((msg_body['message_uuid'], 
                                msg_body['context']['request_id'],
                                str(frame.delivery_tag)))
         message = "Start processing message in the queue - [%s:%s] %s"
         LOG.info(message, msg_id, msg_req_id, body)
         emit([body], id=msg_req_id)        
Example #5
0
    def do_alarm_action(self, alarmkey, alarm, new_state, old_state, query_date):
        """
        parameter example:
        
        alarmkey: f459c0e0-f927-481f-9158-deb8abe102a2 
        alarm: OrderedDict([('actions_enabled', False), 
                            ('alarm_actions', u'[]'), 
                            ('alarm_arn', u'arn:spcs:synaps:IaaS:alarm:TEST_\uc54c\ub78c_02'), 
                            ('alarm_configuration_updated_timestamp', datetime.datetime(2012, 8, 25, 10, 51, 38, 469000)), 
                            ('alarm_description', u''), 
                            ('alarm_name', u'TEST_\uc54c\ub78c_02'), 
                            ('comparison_operator', u'LessThanThreshold'), 
                            ('dimensions', u'{"instance_name": "test instance"}'), 
                            ('evaluation_periods', 2), 
                            ('insufficient_data_actions', u'[]'), 
                            ('metric_key', UUID('96f19ec9-673b-4237-ae66-1bfde526595c')), 
                            ('metric_name', u'test_metric'), 
                            ('namespace', u'SPCS/SYNAPSTEST'), 
                            ('ok_actions', u'[]'), 
                            ('period', 300), 
                            ('project_id', u'IaaS'), 
                            ('state_reason', u'Threshold Crossed: 2 datapoints were not less than the threshold(2.000000). The most recent datapoints: [55.25, 55.25].'), 
                            ('state_reason_data', u'{"startDate": "2012-08-25T10:30:00.000000", "period": 300, "threshold": 2.0, "version": "1.0", "statistic": "Average", "recentDatapoints": [55.25, 55.25], "queryDate": "2012-08-25T10:32:24.671991"}'), 
                            ('state_updated_timestamp', datetime.datetime(2012, 8, 25, 11, 39, 49, 657449)), 
                            ('state_value', 'OK'), 
                            ('statistic', u'Average'), 
                            ('threshold', 2.0), 
                            ('unit', u'Percent'), 
                            ('reason', u'Threshold Crossed: 3 datapoints were not less than the threshold(2.000000). The most recent datapoints: [75.0, 80.0, 67.625].'), 
                            ('reason_data', '{"startDate": "2012-08-25T11:37:00.000000", "period": 300, "threshold": 2.0, "version": "1.0", "statistic": "Average", "recentDatapoints": [75.0, 80.0, 67.625], "queryDate": "2012-08-25T11:39:49.657449"}')
                            ]) 
        new_state: {'stateReason': u'Threshold Crossed: 3 datapoints were not less than the threshold(2.000000). The most recent datapoints: [75.0, 80.0, 67.625].', 
                    'stateValue': 'OK', 
                    'stateReasonData': {'startDate': '2012-08-25T11:37:00.000000', 'period': 300, 'threshold': 2.0, 'version': '1.0', 'statistic': u'Average', 'recentDatapoints': [75.0, 80.0, 67.625], 'queryDate': '2012-08-25T11:39:49.657449'}} 
        old_state: {'stateReason': u'Insufficient Data: 1 datapoints were unknown.', 
                    'stateReasonData': {u'startDate': u'2012-08-25T11:37:00.000000', u'period': 300, u'recentDatapoints': [55.25], u'version': u'1.0', u'statistic': u'Average', u'threshold': 2.0, u'queryDate': u'2012-08-25T11:39:26.261056'}, 'stateValue': 'INSUFFICIENT_DATA'}
        """

        msg = {
            "state": new_state["stateValue"],
            "subject": "%s state has been changed from %s to %s at %s"
            % (alarm["alarm_name"], old_state["stateValue"], new_state["stateValue"], query_date),
            "body": "%s at %s" % (new_state["stateReason"], query_date),
            "query_date": query_date,
        }
        storm.log("emit to Alarm Action: %s %s" % (alarmkey, msg))
        storm.emit([str(alarmkey), json.dumps(msg)])
Example #6
0
    def nextTuple(self):
        try:
            (method_frame, header_frame, body) = self.channel.basic_get(
                queue="metric_queue", no_ack=True
            )
        except (AMQPConnectionError, AMQPChannelError):
            self.log("AMQP Connection or Channel Error. While get a message.")
            self.connect()
            return

        if method_frame:
            mq_msg_id = method_frame.delivery_tag
            msg_body = json.loads(body)
            msg_id, msg_uuid = msg_body['message_id'], msg_body['message_uuid']
            message = "Start processing message in the queue - [%s:%s] %s"
            self.log(message % (msg_id, msg_uuid, body))
            emit([body], id=msg_uuid)
Example #7
0
    def nextTuple(self):
        now = self.get_now()

        if self.lastchecked != now:
            self.lastchecked = now

            ready_to_evaluate = self.check_counter >= self.warmup_period
            msg_id = "periodic_%s" % str(uuid4())
            body = json.dumps({
                'message_id': CHECK_METRIC_ALARM_MSG_ID,
                'ready_to_evaluate': ready_to_evaluate
            })
            emit([None, body], id=msg_id)
            LOG.info("Periodic monitoring message sent[%s]%s. counter: %d",
                     msg_id, body, self.check_counter)

        else:
            time.sleep(1)
Example #8
0
    def process(self, tup):
        message_buf = tup.values[0]
        message = json.loads(message_buf)

        message_id = message['message_id']
        message_uuid = message['message_uuid']
        LOG.info("start processing msg[%s:%s]" % (message_id, message_uuid))
        
        if message_id == PUT_METRIC_DATA_MSG_ID:
            metric_key = str(self.get_metric_key(message))
            storm.emit([metric_key, message_buf])
        
        elif message_id == PUT_METRIC_ALARM_MSG_ID:
            metric_key = message.get('metric_key')
            storm.emit([metric_key, message_buf])

        elif message_id == DELETE_ALARMS_MSG_ID:
            project_id = message['project_id']
            alarmkeys = message['alarmkeys']
            for alarmkey in alarmkeys:
                try:
                    alarmkey_uuid = UUID(alarmkey)
                    metric_key = self.get_alarm_metric_key(alarmkey_uuid)
                    metric_key = str(metric_key)
                    if metric_key:
                        message['alarmkey'] = alarmkey
                        storm.emit([metric_key, json.dumps(message)])
                except Exception as e:
                    LOG.error("Alarm %s does not exists", alarmkey)

        elif message_id == SET_ALARM_STATE_MSG_ID:
            project_id = message['project_id']
            alarm_name = message['alarm_name']
            alarm_key = self.cass.get_metric_alarm_key(project_id,
                                                       alarm_name)
            if alarm_key:
                alarm = self.cass.get_metric_alarm(alarm_key)
                metric_key = str(alarm['metric_key'])
                storm.emit([metric_key, json.dumps(message)])
Example #9
0
    def process(self, tup):
        message_buf = tup.values[0]
        message = json.loads(message_buf)

        message_id = message['message_id']
        message_uuid = message['message_uuid']
        LOG.info("start processing msg[%s:%s]" % (message_id, message_uuid))

        if message_id == PUT_METRIC_DATA_MSG_ID:
            metric_key = str(self.get_metric_key(message))
            storm.emit([metric_key, message_buf])

        elif message_id == PUT_METRIC_ALARM_MSG_ID:
            metric_key = message.get('metric_key')
            storm.emit([metric_key, message_buf])

        elif message_id == DELETE_ALARMS_MSG_ID:
            project_id = message['project_id']
            alarmkeys = message['alarmkeys']
            for alarmkey in alarmkeys:
                try:
                    alarmkey_uuid = UUID(alarmkey)
                    metric_key = self.get_alarm_metric_key(alarmkey_uuid)
                    metric_key = str(metric_key)
                    if metric_key:
                        message['alarmkey'] = alarmkey
                        storm.emit([metric_key, json.dumps(message)])
                except Exception as e:
                    LOG.error("Alarm %s does not exists", alarmkey)

        elif message_id == SET_ALARM_STATE_MSG_ID:
            project_id = message['project_id']
            alarm_name = message['alarm_name']
            alarm_key = self.cass.get_metric_alarm_key(project_id, alarm_name)
            if alarm_key:
                alarm = self.cass.get_metric_alarm(alarm_key)
                metric_key = str(alarm['metric_key'])
                storm.emit([metric_key, json.dumps(message)])
Example #10
0
 def emit(self, tup):
     storm.emit(tup)
     self.log("Emitted %s" % tup)
Example #11
0
    def do_alarm_action(self, alarmkey, alarm, new_state, old_state,
                        query_date):
        """
        parameter example:
        
        alarmkey: f459c0e0-f927-481f-9158-deb8abe102a2 
        alarm: OrderedDict([('actions_enabled', False), 
                            ('alarm_actions', u'[]'), 
                            ('alarm_arn', u'arn:spcs:synaps:IaaS:alarm:TEST_\uc
                            54c\ub78c_02'), 
                            ('alarm_configuration_updated_timestamp', datetime.
                            datetime(2012, 8, 25, 10, 51, 38, 469000)), 
                            ('alarm_description', u''), 
                            ('alarm_name', u'TEST_\uc54c\ub78c_02'), 
                            ('comparison_operator', u'LessThanThreshold'), 
                            ('dimensions', u'{"instance_name": "test instance"}
                            '), 
                            ('evaluation_periods', 2), 
                            ('insufficient_data_actions', u'[]'), 
                            ('metric_key', UUID('96f19ec9-673b-4237-ae66-1bfde5
                            26595c')), 
                            ('metric_name', u'test_metric'), 
                            ('namespace', u'SPCS/SYNAPSTEST'), 
                            ('ok_actions', u'[]'), 
                            ('period', 300), 
                            ('project_id', u'IaaS'), 
                            ('state_reason', u'Threshold Crossed: 2 datapoints 
                            were not less than the threshold(2.000000). The 
                            most recent datapoints: [55.25, 55.25].'), 
                            ('state_reason_data', u'{"startDate": "2012-08-25T
                            10:30:00.000000", "period": 300, "threshold": 2.0, 
                            "version": "1.0", "statistic": "Average", "recentD
                            atapoints": [55.25, 55.25], "queryDate": "2012-08-
                            25T10:32:24.671991"}'), 
                            ('state_updated_timestamp', datetime.datetime(2012,
                             8, 25, 11, 39, 49, 657449)), 
                            ('state_value', 'OK'), 
                            ('statistic', u'Average'), 
                            ('threshold', 2.0), 
                            ('unit', u'Percent'), 
                            ('reason', u'Threshold Crossed: 3 datapoints were 
                            not less than the threshold(2.000000). The most 
                            recent datapoints: [75.0, 80.0, 67.625].'), 
                            ('reason_data', '{"startDate": "2012-08-25T11:37:00
                            .000000", "period": 300, "threshold": 2.0, 
                            "version": "1.0", "statistic": "Average", 
                            "recentDatapoints": [75.0, 80.0, 67.625], 
                            "queryDate": "2012-08-25T11:39:49.657449"}')
                            ]) 
        new_state: {'stateReason': u'Threshold Crossed: 3 datapoints were not 
                                     less than the threshold(2.000000). The 
                                     most recent datapoints: [75.0, 80.0, 
                                     67.625].', 
                    'stateValue': 'OK', 
                    'stateReasonData': {'startDate': '2012-08-25T11:37:00', 
                    'period': 300, 'threshold': 2.0, 'version': '1.0', 
                    'statistic': u'Average', 'recentDatapoints': [75.0, 80.0, 
                    67.625], 
                    'queryDate': '2012-08-25T11:39:49.657449'}} 
        old_state: {'stateReason': u'Insufficient Data: 1 datapoints were 
                                    unknown.', 
                    'stateReasonData': {u'startDate': 
                    u'2012-08-25T11:37:00.000000', 
                    u'period': 300, u'recentDatapoints': [55.25], 
                    u'version': u'1.0', 
                    u'statistic': u'Average', u'threshold': 2.0, 
                    u'queryDate': u'2012-08-25T11:39:26.261056'}, 
                    'stateValue': 'INSUFFICIENT_DATA'}
        """

        msg = {
            'state':
            new_state['stateValue'],
            'subject':
            "%s state has been changed from %s to %s at %s" %
            (alarm['alarm_name'], old_state['stateValue'],
             new_state['stateValue'], query_date),
            'body':
            "%s at %s" % (new_state['stateReason'], query_date),
            'query_date':
            query_date,
            'alarm_description':
            alarm['alarm_description'],
        }
        LOG.info("emit to Alarm Action: %s %s", alarmkey, msg)
        storm.emit([str(alarmkey), json.dumps(msg)])