Xymon Mailing List Archive search

email add-on other than html_mail.pl?

5 messages in this thread

list Becker Christian · Tue, 24 Mar 2020 15:33:54 +0000 ·
Hello to the list,

i'm looking for another email add-on to Xymon (or another script) other than html_mail.pl which I'm currently using.
The html_mail.pl works fine, but now I'm in the situation to send emails to a MS Teams subchannel, and the result is useless, because it's totally mis-formatted in MS Teams.

I tried using the Xymon built-in mail function without html_mail.pl, but this is also not really nice, I'ld like to have at least the red / yellow / green icons together with a black background.
My knowledge isn't good enough to modify html_mail.pl to my needs.

Any idea?


Stay at home - stay healthy!


Best regards from Germany
Christian
list Fabian Wendlandt · Tue, 24 Mar 2020 15:55:17 +0000 ·
Hi Christian,

I'm using the following setup to post Xymon messages to an incoming webhook of a Teams channel.

Create a bash script send-teamsnotification.sh, replace the webhook URL and the path to the json template:
###########################################################
#!/bin/bash

# Incoming webhook of the teams channel
URI='https://outlook.office.com/webhook/<some-long-uid>@<another-uid>/IncomingWebhook/<one-more-uid>/<the-final-uid>';

# Prepend newlines with three spaces to display correctly in teams
BBALPHAMSG="${BBALPHAMSG//$'\n'/'   \n'}"

# Replace variables in the json template (replace the path to the template)
TMPFILE=$(mktemp)
envsubst < /path/to/teamsmsg.json > "$TMPFILE"

# Post message to teams channel
curl -X POST -H 'Content-Type: application/json' -d @${TMPFILE} "$URI"

rm -f $TMPFILE
###########################################################


Put the teamsmsg.json template somewhere on your xymon host, replace the Xymon hostname with your own:
###########################################################
{
    "title": "Alert for $BBHOSTSVC",
    "sections": [
        {
            "activitySubtitle": "$BBHOSTSVC is $BBCOLORLEVEL",
            "activityImage": "https://<xymon-hostname>/gifs/${BBCOLORLEVEL}.gif";,
            "activityTitle": "$BBHOSTSVC",
            "activityText": "Status of service $BBSVCNAME on $BBHOSTNAME changed to $BBCOLORLEVEL"
        },
        {
            "facts": [
                {
                    "value": "$BBHOSTNAME",
                    "name": "Hostname"
                },
                {
                    "value": "$BBSVCNAME",
                    "name": "Service"
                },
                {
                    "value": "$BBCOLORLEVEL",
                    "name": "Color"
                },
                {
                    "value": "$BBALPHAMSG",
                    "name": "Message"
                }
            ],
            "title": "Details"
        }
    ],
    "potentialAction": [
        {
            "@context": "http://schema.org";,
            "name": "Click here to visit the status page",
            "target": [
                "http://<xymon-hostname>/xymon-cgi/svcstatus.sh?HOST=${BBHOSTNAME}&SERVICE=${BBSVCNAME}";
            ],
            "@type": "ViewAction"
        }
    ],
    "text": "Status of service $BBSVCNAME on $BBHOSTNAME changed to $BBCOLORLEVEL"
}
###########################################################


Configure alerts.cfg to send alerts to a script recipient (the parameter 'param' is just there because Xymon expects it, it has no effect), replace the path to the script:
###########################################################
HOST=hostname.fqdn.com SERVICE=http COLOR=red
    SCRIPT /path/to/send-teamsnotification.sh param FORMAT=PLAIN
###########################################################


The resulting notification includes animated gifs of the status color, a clickable button with a link to the service page and includes an expendable status message.
You're Xymon host must be reachable via https, otherwise the gif won't display.

Best regards,
Fabian Wendlandt
quoted from Becker Christian


Von: Xymon <xymon-bounces at xymon.com> Im Auftrag von Becker Christian
Gesendet: Dienstag, 24. M?rz 2020 16:34
An: xymon at xymon.com
Betreff: [Xymon] email add-on other than html_mail.pl?

Hello to the list,

i'm looking for another email add-on to Xymon (or another script) other than html_mail.pl which I'm currently using.
The html_mail.pl works fine, but now I'm in the situation to send emails to a MS Teams subchannel, and the result is useless, because it's totally mis-formatted in MS Teams.

I tried using the Xymon built-in mail function without html_mail.pl, but this is also not really nice, I'ld like to have at least the red / yellow / green icons together with a black background.
My knowledge isn't good enough to modify html_mail.pl to my needs.

Any idea?


Stay at home - stay healthy!


Best regards from Germany
Christian
list Scot Kreienkamp · Tue, 24 Mar 2020 15:59:40 +0000 ·

Scot Kreienkamp | Senior Systems Engineer | La-Z-Boy Corporate
One La-Z-Boy Drive | Monroe, Michigan 48162 | * XXX-XXX-XXXX | |  * X-XXX-XXX-XXXX  | * user-9678697f1438@xymon.invalid
www.la-z-boy.com<http://www.la-z-boy.com>;  | facebook.com/lazboy<http://facebook.com/lazboy>;  | twitter.com/lazboy<http://twitter.com/lazboy>; | youtube.com/lazboy<http://youtube.com/lazboy>;
[cid:4C-lzbVertical_Tag_400px_d8b9412e-f3ea-46a1-99dc-a7c57261e11e.jpg]
From: Xymon <xymon-bounces at xymon.com> On Behalf Of Becker Christian
Sent: Tuesday, March 24, 2020 11:34 AM
To: xymon at xymon.com
Subject: [Xymon] email add-on other than html_mail.pl?

ATTENTION:   This email was sent to La-Z-Boy from an external source.     Be vigilant when opening attachments or clicking links.
quoted from Fabian Wendlandt
Hello to the list,

i'm looking for another email add-on to Xymon (or another script) other than html_mail.pl which I'm currently using.
The html_mail.pl works fine, but now I'm in the situation to send emails to a MS Teams subchannel, and the result is useless, because it's totally mis-formatted in MS Teams.

I tried using the Xymon built-in mail function without html_mail.pl, but this is also not really nice, I'ld like to have at least the red / yellow / green icons together with a black background.
My knowledge isn't good enough to modify html_mail.pl to my needs.

Any idea?


Stay at home - stay healthy!


Best regards from Germany
Christian

[Scot Kreienkamp]

Here's a simple HTML email template I wrote in bash script a few years ago.  You can customize it to your needs quite easily.

#!/bin/bash

SENDEMAIL="/usr/sbin/sendmail -f user-90716007b8c8@xymon.invalid -t"
EMBOUND=asdf1234


$SENDEMAIL << EOF
To: ${RCPT}
From: user-98e7dbae8497@xymon.invalid
Subject: ${SUBJECT}
Content-Type: multipart/related;
        boundary=${EMBOUND};
        type="Text/HTML"
MIME-Version: 1.0
--${EMBOUND}
Content-Type: text/html; charset=US-ASCII

<html>
<body>

<pre>
Pre-formatted text here
</pre>

HTML here

</body>
</html>

EOF


This message is intended only for the individual or entity to which it is addressed. It may contain privileged, confidential information which is exempt from disclosure under applicable laws. If you are not the intended recipient, you are strictly prohibited from disseminating or distributing this information (other than to the intended recipient) or copying this information. If you have received this communication in error, please notify us immediately by e-mail or by telephone at the above number. Thank you.
list Glauber Ribeiro · Tue, 24 Mar 2020 19:25:41 +0000 ·
I didn't know about this script. Thanks. I was about to write something similar, but what has always stopped me is that it seems (from the documentation) that for script alert rules, Xymon supports only one recipient. It my reading correct? 

We use macros like

PAGER_GROUP = user-89ededacf16f@xymon.invalid user-8716922fe3cf@xymon.invalid user-e2b4d8be0765@xymon.invalid

And that works great for the MAIL rules.

How would a SCRIPT rule handle this? Would the script be called multiple times?

Thanks again,

Glauber

(sorry if my email shows up as an attachment - I'm still trying to figure out what is causing this)
list Fabian Wendlandt · Tue, 24 Mar 2020 19:45:25 +0000 ·
Hi,

alerts.cfg invokes any script with the string specified after the script path as parameter.
From the man page:

SCRIPT /path/to/script recipientID Recipient that invokes a script. This takes two parameters: The script filename, and the recipient that gets passed to the script.


I see no reason why receipientID could not contain a list of recipient, although you'd probably have to put some logic into your script to split/parse them, something like this:

In your alerts.cfg:
##########
SCRIPT /path/to/script.sh 'user-c59f6a86ca59@xymon.invalid;user-b7e4b603598a@xymon.invalid'
##########

In the script:
###########
#/bin/bash

IFS=";"
recipients="$1"

for r in "$recipients"; do
	send-stuff-to "$r"
done
##########

Good luck with escaping the Teams webhook URIs, though :)

Best regards,
Fabian Wendlandt


-----Urspr?ngliche Nachricht-----
quoted from Glauber Ribeiro
Von: Ribeiro, Glauber <user-59d088777028@xymon.invalid> 
Gesendet: Dienstag, 24. M?rz 2020 20:26
An: Fabian Wendlandt <user-a63c2f5e765a@xymon.invalid>; 'Becker Christian' <user-e4a19bfb94c0@xymon.invalid>
Cc: xymon at xymon.com
Betreff: RE: email add-on other than html_mail.pl?

I didn't know about this script. Thanks. I was about to write something similar, but what has always stopped me is that it seems (from the documentation) that for script alert rules, Xymon supports only one recipient. It my reading correct? 

We use macros like

PAGER_GROUP = user-89ededacf16f@xymon.invalid user-8716922fe3cf@xymon.invalid user-e2b4d8be0765@xymon.invalid

And that works great for the MAIL rules.

How would a SCRIPT rule handle this? Would the script be called multiple times?

Thanks again,

Glauber

(sorry if my email shows up as an attachment - I'm still trying to figure out what is causing this)