topic_watcher.agent module

class topic_watcher.agent.AlertAgent(config_path, **kwargs)[source]

Bases: volttron.platform.vip.agent.Agent

create_alert_group(group_name, config)[source]
decrement_ttl()[source]

Periodic call

Used to maintain the time since each topic’s last publish. Sends an alert if any topics are missing.

ignore_topic(group, topic)[source]

RPC method

Remove a topic from agent’s watch list. Alerts will no longer be sent if a topic stops being published.

Parameters
  • group (str) – Group that should ignore the topic.

  • topic (str) – Topic to remove from the watch list.

onstart(sender, **kwargs)[source]

Setup database tables for persistent logs

onstop(sender, **kwargs)[source]
property remote_agent
reset_remote_agent()[source]
watch_device(group, topic, timeout, points)[source]

RPC method

Watch a device’s ALL topic and expect points. If the given group is new creates and starts an instance of group agent for the new group. The group onstart will start watching for the given device points

Pararm group

Group that should watch the device.

Parameters
  • topic (str) – Topic expected to be published.

  • timeout (int) – Seconds before an alert is sent.

  • points ([str]) – Points to expect in the publish message.

watch_topic(group, topic, timeout)[source]

RPC method

Listen for a topic to be published within a given number of seconds or send alerts. If the given group is new creates and starts an instance of AlertGroup agent for the new group. The alert group agent, onstart, will start watching for the given topics

Pararm group

Group that should watch the topic.

Parameters
  • topic (str) – Topic expected to be published.

  • timeout (int) – Seconds before an alert is sent.

class topic_watcher.agent.AlertGroup(group_name, config, connection, main_agent, publish_local=True, publish_remote=False)[source]

Bases: object

static get_topic_name(parts)[source]

Return the input parameter if input parameter is a string. If input parameter is a tuple, expects an all topic as the first list element and point name as the second element of the tuple. strips “all” from the end of topic name and add the point name to it to get point topic string :param parts: topic name or (all topic, point name) :type parts: str or list :return: topic string :rtype: str

ignore_topic(topic)[source]

Remove a topic from the group watchlist

Parameters

topic (str) – Topic to remove from the watch list.

log_time_up(up_time, log_topics)[source]

Log into topic_log table when the alert agent found publishes to a topic after the last time it timed out. :param up_time: Time when message was published to the topic. Note that this need not be the same as the timestamp in message header which gets recorded in the historian. For example, when older device scrapes are replayed. :param log_topics: The list of configured topics for which message was received. Entries in this list can either be topic string or a tuple containing an all topic and a point name. :type up_time: datetime :type log_topics: list

log_timeout(log_topics)[source]

logs into database the last time a topic was seen before a time out or current time if topic was never seen from the time of alert agent start. :param log_topics: The list of configured topics for which message was received. Entries in this list can either be topic string or a tuple containing an all topic and a point name. :type log_topics: list

parse_config()[source]
reset_time(peer, sender, bus, topic, headers, message)[source]

Callback for topic subscriptions

Resets the timeout for topics and devices when publishes are received.

restart_timer()[source]

Reset timer for all topics in this alert group. Should be called when a new topic is added to a currently active alert group

send_alert(unseen_topics)[source]

Send an alert for the group, summarizing missing topics.

Parameters

unseen_topics (list) – List of topics that were expected but not received

watch_device(topic, timeout, points)[source]

Watch a device’s ALL topic and expect points. This method calls the watch topic method so both methods don’t need to be called.

Parameters
  • topic (str) – Topic expected to be published.

  • timeout (int) – Seconds before an alert is sent.

  • points ([str]) – Points to expect in the publish message.

watch_topic(topic, timeout)[source]

Listen for a topic to be published within a given number of seconds or send alerts.

Parameters
  • topic (str) – Topic expected to be published.

  • timeout (int) – Seconds before an alert is sent.

topic_watcher.agent.main()[source]