(self, metrics)
Save measurement on database

        Args:
            metrics : Dictionary with receiver metrics to send over the report
Save measurement on database
Save measurement on database
def send(self, metrics):
        """Save measurement on database

        Args:
            metrics : Dictionary with receiver metrics to send over the report
        """
        # When the receiver is not registered with the monitoring API, the
        # sign-up procedure runs. However, this procedure can only work if the
        # receiver is locked, given that it requires reception of a validation
        # code sent exclusively over satellite. Hence, the registration routine
        # (running on a thread) waits until a threading event is set below to
        # indicate the Rx lock:
        if (self.bs_monitoring and not self.bs_monitoring.registered):
            if ('lock' in metrics and metrics['lock']):
                self.bs_monitoring.rx_lock_event.set()

            # If the registration procedure has already stopped and failed, do
            # not proceed. Reporting would otherwise fail anyway, given that
            # the monitoring server does not accept reports from non-registered
            # receivers. Just warn the user and stop right here.
            if (self.bs_monitoring.registration_failure):
                print()
                logger.error("Report failed: registration incomplete "
                             "(relaunch receiver and try again)")

            # Don't send reports to the monitoring API until the receiver is
            # properly registered and verified
            return

        data = {}
        data.update(metrics)

        # When reporting to Blockstream's Monitoring API, sign every set of
        # reported data using the local GPG key and don't send the satellite
        # nor the hostname on the requests. This information is already
        # associated with the account registered with the Monitoring API. In
        # contrast, when reporting to a general-purpose server, do include the
        # satellite and hostname information if defined.
        if (self.bs_monitoring is None):
            data["satellite"] = self.satellite,
            if (self.hostname):
                data['hostname'] = self.hostname
        else:
            self.bs_monitoring.sign_report(data)

        logger.debug("Report {} to {}".format(data, self.dest_addr))

        try:
            r = requests.post(self.dest_addr,
                              json=data,
                              cert=(self.tls_cert, self.tls_key))
            if (r.status_code != requests.codes.ok):
                print()
                logger.error("Report failed: " + r.text)
        except requests.exceptions.ConnectionError as e:
            print()
            logger.error("Report failed: " + str(e))
def send ( self , metrics ) : # When the receiver is not registered with the monitoring API, the # sign-up procedure runs. However, this procedure can only work if the # receiver is locked, given that it requires reception of a validation # code sent exclusively over satellite. Hence, the registration routine # (running on a thread) waits until a threading event is set below to # indicate the Rx lock: if ( self . bs_monitoring and not self . bs_monitoring . registered ) : if ( 'lock' in metrics and metrics [ 'lock' ] ) : self . bs_monitoring . rx_lock_event . set ( ) # If the registration procedure has already stopped and failed, do # not proceed. Reporting would otherwise fail anyway, given that # the monitoring server does not accept reports from non-registered # receivers. Just warn the user and stop right here. if ( self . bs_monitoring . registration_failure ) : print ( ) logger . error ( "Report failed: registration incomplete " "(relaunch receiver and try again)" ) # Don't send reports to the monitoring API until the receiver is # properly registered and verified return data = { } data . update ( metrics ) # When reporting to Blockstream's Monitoring API, sign every set of # reported data using the local GPG key and don't send the satellite # nor the hostname on the requests. This information is already # associated with the account registered with the Monitoring API. In # contrast, when reporting to a general-purpose server, do include the # satellite and hostname information if defined. if ( self . bs_monitoring is None ) : data [ "satellite" ] = self . satellite , if ( self . hostname ) : data [ 'hostname' ] = self . hostname else : self . bs_monitoring . sign_report ( data ) logger . debug ( "Report {} to {}" . format ( data , self . dest_addr ) ) try : r = requests . post ( self . dest_addr , json = data , cert = ( self . tls_cert , self . tls_key ) ) if ( r . status_code != requests . codes . ok ) : print ( ) logger . error ( "Report failed: " + r . text ) except requests . exceptions . ConnectionError as e : print ( ) logger . error ( "Report failed: " + str ( e ) )