def publish_compliance(self, state, publish=True):
        """ When a state change is detected, this method publish a message to
        the transport layer.
        """

        msg = ''
        now = datetime.now()
        time_format = '%d/%m/%y %H:%M:%S'
        state['timestamp'] = now.strftime(time_format)

        if state['back_to_compliance'] and state['compliant']:
            state['msg_type'] = 'compliance_ok'
            state['back_to_compliance'] = False
            state['last_alert'] = None
            msg = "is BACK to compliance"

        elif not state['compliant']:
            state['msg_type'] = 'compliance_error'
            msg = "is NOT compliant"
            last_alert = state.get('last_alert')
            if last_alert:
                delta = now - datetime.strptime(last_alert, time_format)
                if delta < self.alert_interval:
                    publish = False
                else:
                    state['last_alert'] = now.strftime(time_format)
            else:
                state['last_alert'] = now.strftime(time_format)


        if publish:
            self.logger.debug("%s (%s) %s." % (state['resource_id'],
                                               state['collection'],
                                               msg))
            msg = OutgoingMessage(**state)
            self.publish(msg)

        self.states_manager.persist()
dataset/ETHPy150Open comodit/synapse-agent/synapse/resources/resources.py/ResourcesController.publish_compliance/original