<?xml version="1.0" encoding="UTF-8"?>

<!-- Differential patch for M/Monit database schema version 24 to 25 -->

<patch>

<!-- sqlite -->

<statements type="sqlite">

<comment>Add pre-defined Alert Script for Microsoft Teams</comment>
<statement>
INSERT INTO alertservice(id, name, description, script, expanded, created_at)
VALUES(4, 'Teams Alert', 'A Service for sending Microsoft Teams Alerts',
'# Generate the Teams message payload using MessageCard format
generate_payload() {
  printf ''{
  "@type": "MessageCard",
  "@context": "https://schema.org/extensions",
  "summary": "M/Monit Alert: %s on %s",
  "themeColor": "D70000",
  "title": "M/Monit Alert",
  "text": "Alert details below:",
  "sections": [
    {
      "facts": [
        {
          "name": "Date",
          "value": "%s"
        },
        {
          "name": "Host",
          "value": "%s"
        },
        {
          "name": "Service",
          "value": "%s"
        },
        {
          "name": "Action",
          "value": "%s"
        },
        {
          "name": "Event",
          "value": "%s"
        }
      ],
      "text": "**Description:** %s"
    }
  ]
}'' "$MONIT_EVENT" "$MONIT_HOST" "$MONIT_DATE" "$MONIT_HOST" "$MONIT_SERVICE" "$MONIT_ACTION" "$MONIT_EVENT" "$MONIT_DESCRIPTION"
}

# Generate and send the payload
payload=$(generate_payload)
curl -H "Content-Type: application/json" -d "$payload" "$ENDPOINT"',
'noop', 1729646970);
</statement>

<comment>Add pre-defined Alert Script for Telegram</comment>
<statement>
<![CDATA[
INSERT INTO alertservice(id, name, description, script, expanded, created_at)
VALUES(5, 'Telegram Alert', 'A Service for sending Telegram Alerts',
'# Generate the Telegram message payload with HTML formatting
generate_payload() {
  printf ''{
    "chat_id": %s,
    "text": "<b>Alert from M/Monit</b>\n\n<pre>%s\n\nHost:    %s\nService: %s\nAction:  %s\n\nEvent:\n%s\n\nDescription:\n%s</pre>",
    "parse_mode": "HTML"
}'' "$ENDPOINT" "$MONIT_DATE" "$MONIT_HOST" "$MONIT_SERVICE" "$MONIT_ACTION" "$MONIT_EVENT" "$MONIT_DESCRIPTION"
}

# Generate and send the payload
payload=$(generate_payload)
curl -X POST \
     -H "Content-Type: application/json" \
     -d "$payload" \
     "https://api.telegram.org/bot$APIKEY/sendMessage"',
'noop', 1723456800);
]]>
</statement>


</statements>

<!-- mysql -->

<statements type="mysql">

<comment>Add pre-defined Alert Script for Microsoft Teams</comment>
<statement>
INSERT INTO alertservice(id, name, description, script, expanded, created_at)
VALUES(4, 'Teams Alert', 'A Service for sending Microsoft Teams Alerts', CONCAT(
'# Generate the Teams message payload using MessageCard format
generate_payload() {
  printf ''{
  "@type": "MessageCard",
  "@context": "https://schema.org/extensions",
  "summary": "M/Monit Alert: %s on %s",
  "themeColor": "D70000",
  "title": "M/Monit Alert",
  "text": "Alert details below:",
  "sections": [
    {
      "facts": [
        {
          "name": "Date",
          "value": "%s"
        },
        {
          "name": "Host",
          "value": "%s"
        },
        {
          "name": "Service",
          "value": "%s"
        },
        {
          "name": "Action",
          "value": "%s"
        },
        {
          "name": "Event",
          "value": "%s"
        }
      ],
      "text": "**Description:** %s"
    }
  ]
}'' "$MONIT_EVENT" "$MONIT_HOST" "$MONIT_DATE" "$MONIT_HOST" "$MONIT_SERVICE" "$MONIT_ACTION" "$MONIT_EVENT" "$MONIT_DESCRIPTION"
}

# Generate and send the payload
payload=$(generate_payload)
curl -H "Content-Type: application/json" -d "$payload" "$ENDPOINT"'
), 'noop', 1730199600);
</statement>

<comment>Add pre-defined Alert Script for Telegram</comment>
<statement>
<![CDATA[
INSERT INTO alertservice(id, name, description, script, expanded, created_at)
VALUES(5, 'Telegram Alert', 'A Service for sending Telegram Alerts', CONCAT(
'# Generate the Telegram message payload with HTML formatting
generate_payload() {
  printf ''{
    "chat_id": %s,
    "text": "<b>Alert from M/Monit</b>\\n\\n<pre>%s\\n\\nHost:    %s\\nService: %s\\nAction:  %s\\n\\nEvent:\\n%s\\n\\nDescription:\\n%s</pre>",
    "parse_mode": "HTML"
}'' "$ENDPOINT" "$MONIT_DATE" "$MONIT_HOST" "$MONIT_SERVICE" "$MONIT_ACTION" "$MONIT_EVENT" "$MONIT_DESCRIPTION"
}

# Generate and send the payload
payload=$(generate_payload)
curl -X POST \\
  -H "Content-Type: application/json" \\
  -d "$payload" \\
  "https://api.telegram.org/bot$APIKEY/sendMessage"'
), 'noop', 1730199600);
]]>
</statement>

</statements>


<!-- postgresql -->

<statements type="postgresql">

<comment>Add pre-defined Alert Script for Microsoft Teams</comment>
<statement>
INSERT INTO alertservice(id, name, description, script, expanded, created_at)
VALUES(4, 'Teams Alert', 'A Service for sending Microsoft Teams Alerts', $script$
# Generate the Teams message payload using MessageCard format
generate_payload() {
  printf '{
  "@type": "MessageCard",
  "@context": "https://schema.org/extensions",
  "summary": "M/Monit Alert: %s on %s",
  "themeColor": "D70000",
  "title": "M/Monit Alert",
  "text": "Alert details below:",
  "sections": [
    {
      "facts": [
        {
          "name": "Date",
          "value": "%s"
        },
        {
          "name": "Host",
          "value": "%s"
        },
        {
          "name": "Service",
          "value": "%s"
        },
        {
          "name": "Action",
          "value": "%s"
        },
        {
          "name": "Event",
          "value": "%s"
        }
      ],
      "text": "**Description:** %s"
    }
  ]
}' "$MONIT_EVENT" "$MONIT_HOST" "$MONIT_DATE" "$MONIT_HOST" "$MONIT_SERVICE" "$MONIT_ACTION" "$MONIT_EVENT" "$MONIT_DESCRIPTION"
}

# Generate and send the payload
payload=$(generate_payload)
curl -H "Content-Type: application/json" -d "$payload" "$ENDPOINT"
$script$, 'noop', 1729646970);
</statement>

<comment>Add pre-defined Alert Script for Telegram</comment>
<statement>
<![CDATA[
INSERT INTO alertservice(id, name, description, script, expanded, created_at)
VALUES(5, 'Telegram Alert', 'A Service for sending Telegram Alerts', $script$
# Generate the Telegram message payload with HTML formatting
generate_payload() {
printf '{
    "chat_id": %s,
    "text": "<b>Alert from M/Monit</b>\n\n<pre>%s\n\nHost:    %s\nService: %s\nAction:  %s\n\nEvent:\n%s\n\nDescription:\n%s</pre>",
    "parse_mode": "HTML"
}' "$ENDPOINT" "$MONIT_DATE" "$MONIT_HOST" "$MONIT_SERVICE" "$MONIT_ACTION" "$MONIT_EVENT" "$MONIT_DESCRIPTION"
}

# Generate and send the payload
payload=$(generate_payload)
curl -X POST \
    -H "Content-Type: application/json" \
    -d "$payload" \
    "https://api.telegram.org/bot$APIKEY/sendMessage"
$script$, 'noop', 1723456800);
]]>
</statement>

</statements>

</patch>


