Adding Information to Notification-EMails

Hi,

Nwc_health Line wrapping notifications don´t work might inspire you in terms of such a script.

There’s a few steps involved in order to pass details to a script:

  • Ensure that the notification script reads parameters from the CLI or via environment variable - you can test that standalone on your terminal.
  script.sh --notes="...." --notes-url="..."

Depending on the script language you’re using, you’ll need to implement and extend getopts for this.

  • Extend the NotificationCommand and add additional arguments with using the previously added script parameters. Use placeholder runtime macros, you’ll need them in the actual notification object later.
  "--notes" = {
     description = "Host/Service notes"
     value = "$notification_notes$"
  }
  "--notes-url" = {
     description "Host/Service notes_url"
     value = "$notification_notes_url$"
  }
  • Adopt the notification (apply rule) config, add the required custom attributes.
apply Notification "..." to Service {
  ...

  if (service.notes != "") {
    vars.notification_notes = service.notes
  } else if (host.notes != "") {
     vars.notification_nodes = host.notes //fallback
  }
  if (service.notes_url != "") {
    vars.notification_notes_url = service.notes_url
  } else if (host.notes_url != "") {
    vars.notification_notes_url = host.notes_url //fallback
  }

  ...
}

apply Notification "..." to Host {
  ...
  if (host.notes != "") {
    vars.notification_notes = host.notes
  }

  if (host.notes_url != "") {
    vars.notification_notes_url = host.notes_url
  }

  ...

}

Cheers,
Michael