flexmeasures.cli.monitor

CLI commands for monitoring functionality.

Functions

flexmeasures.cli.monitor.automation_page_url(automation) → str | None

Link to the Automations page of the automation’s asset, opening that automation’s info, if the server knows its own address.

flexmeasures.cli.monitor.compose_automation_digest(failures: list[AutomationFailures], stuck_after: timedelta, for_host: bool = True, skips: list[AutomationSkips] = (), reader: User | None = None) → tuple[str, str]

Return the subject and body of a digest about these failed and skipped automations.

Parameters:
  • for_host – Whether the digest goes to the host, who can check the logs, rather than to a user of the assets’ organisations.

  • skips – The runs skipped because of another organisation’s automation, collapsed per automation.

  • reader – The user the digest goes to, if not the host (see describe_automation_skips).

flexmeasures.cli.monitor.describe_automation_failures(failures: AutomationFailures) → str

Describe the failed runs of one automation in a few lines, for the monitoring digest.

flexmeasures.cli.monitor.describe_automation_skips(skips: AutomationSkips, reader: User | None = None) → str

Describe the runs of one automation skipped because of another organisation’s automation, in a few lines, for the monitoring digest.

Each run comes with the runs of its organisation skipped because of it, and the error of the upstream run it was skipped for.

Parameters:

reader – The user the digest goes to, who only gets to see what they may read, or None for the host, who sees everything.

flexmeasures.cli.monitor.get_absent_users(last_seen_delta: timedelta, account_ids: list[int], client_account_ids: list[int] | None = None, account_role: str | None = None, user_role: str | None = None) → list[User]

Get users whose last contact is too old, narrowed down by account and role filters.

flexmeasures.cli.monitor.get_default_monitoring_email_recipients()
flexmeasures.cli.monitor.get_monitoring_email_recipients(recipients: tuple[str, ...] = ()) → list[str]
flexmeasures.cli.monitor.send_automation_digests_to_users(failures: list[AutomationFailures], stuck_after: timedelta, skips: list[AutomationSkips] = ())

Email each account admin and consultant a digest of the failed and skipped automations they may read.

The runs are already marked as reported, so a digest that cannot be sent is logged rather than tried again.

flexmeasures.cli.monitor.send_lastseen_monitoring_alert(users: list[User], last_seen_delta: timedelta, alerted_users: bool, account_ids: list[int] | None = None, client_account_ids: list[int] | None = None, consultant_account_id: int | None = None, account_role: str | None = None, user_role: str | None = None, txt_about_already_alerted_users: str = '', email_recipients: list[str] | None = None)

Tell monitoring recipients and Sentry about user(s) we haven’t seen in a while.

flexmeasures.cli.monitor.send_task_monitoring_alert(task_name: str, msg: str, latest_run: LatestTaskRun | None = None, custom_msg: str | None = None, email_recipients: list[str] | None = None)

Send any monitoring message per Sentry and per email. Also log an error.