How to use the protobuf.pb_util.build_gc_update function in protobuf

To help you get started, we’ve selected a few protobuf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openpowerquality / opq / mauka / plugins / outage_plugin_new.py View on Github external
del self.prev_incident_ids[box_id]
                            continue

                        # Fresh outage
                        if box_id not in self.prev_incident_ids:
                            incident_id = mongo.store_incident(-1,
                                                               box_id,
                                                               int(unix_time_millis(now)),
                                                               -1,
                                                               mongo.IncidentMeasurementType.HEALTH,
                                                               -1.0,
                                                               [mongo.IncidentClassification.OUTAGE],
                                                               opq_mongo_client=self.mongo_client,
                                                               copy_data=False)
                            # Produce a message to the GC
                            self.produce(Routes.laha_gc, protobuf.pb_util.build_gc_update(self.name,
                                                                                          protobuf.mauka_pb2.INCIDENTS,
                                                                                          incident_id))

                            self.prev_incident_ids[box_id] = incident_id
                        # Ongoing outage
                        else:
                            prev_incident_id = self.prev_incident_ids[box_id]

                            # Update previous incident
                            self.mongo_client.incidents_collection.update_one({"incident_id": prev_incident_id},
                                                                              {"$set": {"end_timestamp_ms": int(unix_time_millis(now))}})
                    else:
                        # Outage over
                        if box_id in self.prev_incident_ids:
                            prev_incident_id = self.prev_incident_ids[box_id]
github openpowerquality / opq / mauka / plugins / annotation_plugin.py View on Github external
def on_message(self, topic: str, mauka_message: protobuf.mauka_pb2.MaukaMessage):
        if protobuf.pb_util.is_annotation_request(mauka_message):
            self.debug("Recv annotation request")
            phenomena_id: int = perform_annotation(self.mongo_client,
                                                   mauka_message.annotation_request.incidents_ids[:],
                                                   mauka_message.annotation_request.event_ids[:],
                                                   mauka_message.annotation_request.annotation,
                                                   mauka_message.annotation_request.start_timestamp_ms,
                                                   mauka_message.annotation_request.end_timestamp_ms)

            self.debug(f"Made phenomena with id={phenomena_id}")

            gc_update = protobuf.pb_util.build_gc_update(self.name,
                                                         protobuf.mauka_pb2.PHENOMENA,
                                                         phenomena_id)
            self.debug(f"Preparing to send gc_update={str(gc_update)}")

            self.produce(Routes.laha_gc, gc_update)
        else:
            self.logger.error("Received incorrect message type for AnnotationPlugin: %s", str(mauka_message))
github openpowerquality / opq / mauka / plugins / ieee1159_voltage_plugin.py View on Github external
def on_message(self, topic, mauka_message):
        """
        Called async when a topic this plugin subscribes to produces a message
        :param topic: The topic that is producing the message
        :param mauka_message: The message that was produced
        """
        self.debug("on_message")
        if protobuf.pb_util.is_payload(mauka_message, protobuf.mauka_pb2.VOLTAGE_RMS_WINDOWED):
            incident_ids = ieee1159_voltage(mauka_message, self.mongo_client, self)
            for incident_id in incident_ids:
                # Produce a message to the GC
                self.produce(Routes.laha_gc, protobuf.pb_util.build_gc_update(self.name,
                                                                              protobuf.mauka_pb2.INCIDENTS,
                                                                              incident_id))

        else:
            self.logger.error("Received incorrect mauka message [%s] at IticPlugin",
                              protobuf.pb_util.which_message_oneof(mauka_message))
github openpowerquality / opq / mauka / plugins / thd_plugin.py View on Github external
def on_message(self, topic, mauka_message):
        """
        Fired when this plugin receives a message. This will wait a certain amount of time to make sure that data
        is in the database before starting thd calculations.
        :param topic: Topic of the message.
        :param mauka_message: Contents of the message.
        """
        if protobuf.pb_util.is_payload(mauka_message, protobuf.mauka_pb2.ADC_SAMPLES):
            self.debug("on_message {}:{} len:{}".format(mauka_message.payload.event_id,
                                                        mauka_message.payload.box_id,
                                                        len(mauka_message.payload.data)))
            incident_ids = thd(mauka_message, self.threshold_percent, self.mongo_client, self)

            for incident_id in incident_ids:
                # Produce a message to the GC
                self.produce(Routes.laha_gc, protobuf.pb_util.build_gc_update(self.name,
                                                                              protobuf.mauka_pb2.INCIDENTS,
                                                                              incident_id))
        else:
            self.logger.error("Received incorrect mauka message [%s] at ThdPlugin",
                              protobuf.pb_util.which_message_oneof(mauka_message))
github openpowerquality / opq / mauka / plugins / semi_f47_plugin.py View on Github external
def on_message(self, topic: str, mauka_message: protobuf.mauka_pb2.MaukaMessage):
        if protobuf.pb_util.is_payload(mauka_message, protobuf.mauka_pb2.VOLTAGE_RMS_WINDOWED):
            self.debug("Recv windowed voltage")
            incident_ids = semi_violation(self.mongo_client, mauka_message, self)
            for incident_id in incident_ids:
                # Produce a message to the GC
                self.produce(Routes.laha_gc, protobuf.pb_util.build_gc_update(self.name,
                                                                              protobuf.mauka_pb2.INCIDENTS,
                                                                              incident_id))
github openpowerquality / opq / mauka / plugins / makai_event_plugin.py View on Github external
def on_message(self, topic, mauka_message):
        if protobuf.pb_util.is_makai_event_message(mauka_message):
            self.debug("on_message: {}".format(mauka_message))
            timer = threading.Timer(self.get_data_after_s,
                                    function=self.acquire_and_produce,
                                    args=[mauka_message.makai_event.event_id])

            # Produce a message to the GC
            self.debug("Producing laha_gc update")
            self.produce(Routes.laha_gc,
                         protobuf.pb_util.build_gc_update(self.name, protobuf.mauka_pb2.EVENTS,
                                                          mauka_message.makai_event.event_id))
            self.debug("laha_gc update produced")
            timer.start()
        else:
            self.logger.error("Received incorrect mauka message [%s] for MakaiEventPlugin",
                              protobuf.pb_util.which_message_oneof(mauka_message))
github openpowerquality / opq / mauka / plugins / itic_plugin.py View on Github external
def on_message(self, topic, mauka_message):
        """
        Called async when a topic this plugin subscribes to produces a message
        :param topic: The topic that is producing the message
        :param mauka_message: The message that was produced
        """
        if protobuf.pb_util.is_payload(mauka_message, protobuf.mauka_pb2.VOLTAGE_RMS_WINDOWED):
            self.debug("Recv RmwWindowedVoltage")
            incident_ids = itic(mauka_message,
                                self.segment_threshold,
                                self,
                                self.mongo_client)

            for incident_id in incident_ids:
                # Produce a message to the GC
                self.produce(Routes.laha_gc, protobuf.pb_util.build_gc_update(self.name,
                                                                              protobuf.mauka_pb2.INCIDENTS,
                                                                              incident_id))
        else:
            self.logger.error("Received incorrect mauka message [%s] at IticPlugin",
                              protobuf.pb_util.which_message_oneof(mauka_message))
github openpowerquality / opq / mauka / plugins / outage_plugin.py View on Github external
{"$set": {"end_timestamp_ms": int(now)}})
                    # No outage
                    else:
                        self.debug("No outage for box_id=%s" % box_id)
                        # Outage over
                        if box_id in self.prev_incident_ids:
                            prev_incident_id = self.prev_incident_ids[box_id]
                            self.debug("Outage over incident_id=%d box_id=%s" % (prev_incident_id, box_id))

                            # Update previous incident
                            self.mongo_client.incidents_collection.update_one(
                                {"incident_id": prev_incident_id},
                                {"$set": {"end_timestamp_ms": int(box_to_min_timestamp[box_id])}})

                            # Produce a message to the GC
                            self.produce(Routes.laha_gc, protobuf.pb_util.build_gc_update(self.name,
                                                                                          protobuf.mauka_pb2.INCIDENTS,
                                                                                          prev_incident_id))
                            del self.prev_incident_ids[box_id]

                self.last_update = now