Skip to main content

Self-Healing

A self-healing rule runs a script from the library on a host when an alert opens, before anybody is told. Most faults that wake someone up are small and well known — a service that fell over, a log directory that filled up — and the fix is a command. If the script fixes the problem, nobody is disturbed and the timeline says what happened. If it does not, the usual notification goes out, and says that a repair was tried.

Rules live under Scripts → Self-healing, which the navigation offers to administrators and managers. Each alert rule has a link to its own rules.

What happens when an alert opens​

  1. The alert engine raises the alert. It appears on the alerts page at once; only its notification waits.

  2. If an enabled rule covers the alert's alert rule and host, and the host has attempts left (see Limits), the dashboard submits the rule's script as a job to that host, with the alert handed over as environment variables.

  3. The notification is held until the result is known:

    ResultWhat people get
    The script succeeded and the alert resolvedNothing. No alert mail, no channel message, no webhook for the alert, and no mail that it is over. The timeline records the event remediation.succeeded.
    The script failed, timed out or never reached the host, or it succeeded and the alert is still open when the time to resolve is upThe normal notification, with a line saying that self-healing was attempted and did not resolve the alert, naming the rule and the attempt. The timeline records remediation.failed.
    The alert went away by itself while the script ranNothing; the problem is gone.
    Somebody acknowledged the alert meanwhileNothing further: they already know.
    The host has used up the rule's attemptsThe normal notification, at once, exactly as if there were no rule.
    The rule cannot run: the host has no live link, does not allow scripts, is waiting for approval, or the script is no longer availableThe normal notification, at once.

The remediation events are never mailed by event rules: the alert's own notification is what tells people, or deliberately does not.

How long a notification can wait​

At most the script's timeout plus one minute for the dispatcher to hand the job to the host. After a successful run the alert still has to resolve, which the alert engine judges over the alert rule's duration, so the notification waits for that duration and two minutes more at the longest. A script with a ten minute timeout can therefore hold a notification for about eleven minutes; one that finishes in seconds releases it as soon as the alert resolves, or tells people at the end of the verification time if it does not.

The hold is made by the alert engine, which runs when POST /api/cron/evaluate-alerts is called; see Alert Rules. A failed job releases its notification at once, without waiting for the next run.

Escalations and relapses​

  • An alert that escalates to a stricter level of the same metric counts as a new opening: the rule of the stricter level, if it has one, runs, and the announcement of the escalation waits for it.
  • An alert silenced by a successful repair that comes back within 30 minutes (see Reopened under Alert Rules) starts the rule again if the host has attempts left, and is announced as a new alert if it has not. Nobody was told about it before, so the usual silent reopening would hide a problem that is back.

A rule​

PartMeaning
NameFree text. It is the title of the job's batch on the host's Jobs tab and the name in the marked notification.
Alert ruleThe rule whose alerts this one answers. Several self-healing rules may share one alert rule; the first that has attempts left is used.
ScopeNarrows the alert rule: every host it watches, one customer's, one cluster's or one host's. A scoped rule needs the right to run scripts at that customer (or at each customer in the cluster); an unscoped one is the administrators'.
ScriptA script from the script library and one of its versions. The rule is pinned to that version: a newer version of the script does not run until someone edits the rule.
ParametersThe values of the version's parameters. A secret is stored encrypted and never shown again; leave it empty when editing to keep it.
Attempts per hostHow many times the rule may run for one host and this rule within the period. Default 3, at most 20.
Within (hours)The period, 24 by default, at most 168.
EnabledOff keeps the rule and stops it running.

An attempt is counted when the job is submitted, whatever its outcome, so a script that fails does not get a fourth try the same day. The count is per host: a rule that has given up on one host still runs on the others.

What the script receives​

Besides its own parameters, the script runs with these environment variables. They describe the alert, and everything in them that came from the host — the mount point or unit name of the series — is input to quote in the script, not code.

VariableValue
SELVARA_ALERT_IDThe alert's id.
SELVARA_ALERT_RULEThe name of the alert rule.
SELVARA_ALERT_HOSTThe name of the host in the dashboard.
SELVARA_ALERT_METRICThe metric type, without the series: disk.
SELVARA_ALERT_LABELThe series: /var/log for disk:/var/log, empty for a metric without one.
SELVARA_ALERT_CONDITIONabove or below.
SELVARA_ALERT_VALUEThe value when the alert opened.
SELVARA_ALERT_THRESHOLDThe threshold of the rule that raised it.
SELVARA_ALERT_SERVICEThe service the alert rule is narrowed to, or the unit or Windows service of a unit_active or service_active series; empty otherwise.
SELVARA_ALERT_ATTEMPTWhich attempt this is within the period, from 1.

Control characters are replaced and every value is cut at 256 characters. A script parameter cannot use one of these names: the alert's variables win.

Limits​

  • One attempt at a time per alert. An alert has at most one run under way.
  • Attempts per host, rule and period, as above.
  • Live link. A host that is not linked is not waited for: its notification goes out at once. This includes the alert for a host that stopped reporting.
  • The host's own file. The host runs the script only if its config.yaml allows the script action, like any other script job; see Agent Installation.
  • Four eyes. Where a customer's policy asks for approval, a rule that covers that customer does not run until someone other than its author has approved it, with the check mark on its row. Editing what the rule does — script, version, parameters, alert rule, scope or limits — takes the approval back; renaming and switching it off and on do not. The jobs it starts are then released with that approval and do not wait again.
  • Not over a private customer's hosts on someone else's say-so. A person can write rules for their own private customer like for any customer, but a rule that spans every customer does not start a script on a host there: scripts are not run in a private customer on anyone's behalf.
  • Nobody asks. The job's requester is the dashboard itself, so it appears without a person on the jobs list and in the audit log as remediation.run and remediation.finish, with the rule and the alert.

Where to see what happened​

  • The rule's row shows its last attempt: which host, when, and how it ended.
  • The host's Jobs tab lists the job, with its output, like any other.
  • The host's Alerts tab (view Events) and the timeline show remediation.succeeded and remediation.failed.
  • The audit log records rule changes and approvals, and each run and result of a rule.

Who may do what​

ActionNeeds
See the rulesAdministrator or manager; a manager sees the rules whose scope it reaches, and unscoped ones read-only.
Create, change, enable, disable, deleteManager or administrator, reach over the whole scope, and the script.run permission at every customer the scope covers; an unscoped rule is the administrators'.
ApproveThe same, and not the person who wrote the rule.

See Users and Permissions.

Troubleshooting​

  • The notification came although the script succeeded. The alert did not resolve within the verification time: the alert engine judges the metric over the alert rule's duration, so a value that is back but whose window still holds old samples resolves later. Raise nothing; the next relapse is judged the same way. If the script cannot fix the cause, it is the wrong repair.
  • Nothing ran. Check the rule is enabled and, where the customer asks for four eyes, approved; that the host is linked and allows script; and that the host has not used up its attempts (the rule row shows the limit, the audit log the runs).
  • The marked mail says attempt 3 and nothing more happens. The limit is reached; further alerts of that host are notified normally until the period has passed.
  • An alert opened and nobody was mailed, and it is still open. A run is under way or being verified. Its notification is released when the job ends or the verification time is up; look at the host's jobs.