/**
 * Check MQTT values
 */

object CheckCommand "check_mqtt" {
  import "plugin-check-command"

  command = [ "/opt/check-mqtt/check-mqtt.py" ] 

  arguments = {
    "-H" = "$mqtt_host$"
    "-u" = "$mqtt_user$"
    "-p" = "$mqtt_password$"
    "-P" = "$mqtt_port$"
    "-a" = "$mqtt_cafile$"
    "-C" = "$mqtt_certfile$"
    "-k" = "$mqtt_keyfile$"
    "-t" = "$mqtt_topic$"
    "-m" = {
      set_if = "$mqtt_max$"
      value = "$mqtt_max$"
    }

    "-l" = "$mqtt_payload$"
    "-v" = "$mqtt_value$"
    "-o" = "$mqtt_operator$"

    "-r" = {
      set_if = "$mqtt_readonly$"
      description = "Don't write."
    }
    "-n" = {
      set_if = "$mqtt_insecure$"
      description = "suppress TLS hostname check"
    }
  }
}

/**
 * Check for Mail Blacklisting
 */

object CheckCommand "check_mail_blacklist" {
  import "plugin-check-command"

  command = [ "/opt/check_rbl_helper.sh" ] 

  arguments = {
    "-H" = "$rbl_host$"
    "-c" = "$rbl_critical$"
    "-w" = "$rbl_warning$"
  }
}

/**
 * Check for Prometheus values 
 */

object CheckCommand "check_metric_value" {
  import "plugin-check-command"

  command = [ "/opt/check_metric_value/check_metric_value.py" ] 

  arguments = {
    "-P" = "/opt/prom2json"
    "-U" = "$metric_url$"
    "-M" = "$metric_name$"
    "-n" = "$metric_labelname$"
    "-v" = "$metric_labelvalue$"
    "-o" = "$metric_operator$"
    "-u" = "$metric_unit$"
    "-w" = "$metric_warn$"
    "-c" = "$metric_crit$"
  }
}

/**
 * Matrix Notification 
 */

object NotificationCommand "matrix-host-notification" {
  import "plugin-notification-command"

  command = [ "/opt/icinga2-matrix-bot/icinga2/matrix-host-notification.sh" ]

  env = {
    "NOTIFICATIONTYPE" = "$notification.type$"
    "HOSTALIAS" = "$host.display_name$",
    "HOSTADDRESS" = "$address$",
    "HOSTNAME" = "$host.name$",
    "HOSTSTATE" = "$host.state$",
    "LONGDATETIME" = "$icinga.long_date_time$",
    "HOSTOUTPUT" = "$host.output$",
    "NOTIFICATIONAUTHORNAME" = "$notification.author$",
    "NOTIFICATIONCOMMENT" = "$notification.comment$",
    "HOSTDISPLAYNAME" = "$host.display_name$",
    "ICINGA_WEBURL" = "$notification_icingaweb2url$",
    "MATRIX_SERVER" = "$user.vars.matrix.server$",
    "MATRIX_TOKEN" = "$user.vars.matrix.token$",
    "MATRIX_CHANNEL" = "$user.vars.matrix.channel$",
  }
}

object NotificationCommand "matrix-service-notification" {
  import "plugin-notification-command"

  command = [ "/opt/icinga2-matrix-bot/icinga2/matrix-service-notification.sh" ]

  env = {
    "NOTIFICATIONTYPE" = "$notification.type$"
    "SERVICEDESC" = "$service.name$"
    "HOSTALIAS" = "$host.display_name$",
    "HOSTNAME" = "$host.name$",
    "HOSTADDRESS" = "$address$",
    "SERVICESTATE" = "$service.state$",
    "LONGDATETIME" = "$icinga.long_date_time$",
    "SERVICEOUTPUT" = "$service.output$",
    "NOTIFICATIONAUTHORNAME" = "$notification.author$",
    "NOTIFICATIONCOMMENT" = "$notification.comment$",
    "HOSTDISPLAYNAME" = "$host.display_name$",
    "SERVICEDISPLAYNAME" = "$service.display_name$",
    "ICINGA_WEBURL" = "$notification_icingaweb2url$",
    "MATRIX_SERVER" = "$user.vars.matrix.server$",
    "MATRIX_TOKEN" = "$user.vars.matrix.token$",
    "MATRIX_CHANNEL" = "$user.vars.matrix.channel$",
  }
}