Brevis.one SMS Server

**CMK version:2.3.p31
**OS version:Debian GNU/Linux 12

Hi,

I use the Brevis.one script to send SMS messages via the SMS server. Unfortunately, I don’t have control over the SMS server, and my colleagues have now uploaded a self-signed certificate for HTTPS. Since then, sending SMS messages in CMK has been throwing up this error:

Error sending SMS to XXX: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1010)>

I’m using version 2.3. I’ve already switched to the new Brevis.one script:

When I test the whole thing with curl:

curl -k -s “https://XXX/api.php?username=XXX&password=XXX&to=XXX&text=TEST-SMS

Sending the SMS works.

Can someone help me here? Maybe it’s enough to adjust the Brevis.one script.

Hi,
did you try this:

handle = urllib.request.urlopen(url, verify=False)

This should ignore the error. Otherwise you need to import the certificate to your system.

RG, Christian

1 Like

I added this command, but unfortunately, I got this error message:

Error sending SMS to xxx: urlopen() got an unexpected keyword argument ‘verify’

But I googled “urllib.request.urlopen(url, verify=False)” and found this:

import urllib.request
import ssl

# Create an SSL context that does not verify certificates
ssl_context = ssl._create_unverified_context()

# Use the SSL context with urllib
response = urllib.request.urlopen('<https://example.com>', context=ssl_context)
print(response.read())

So now I have the original Edited the Brevis.one script from the
share/doc/check_mk/treasures/notifications folder like this:

#!/usr/bin/env python3
# brevis.one SMS Gateway
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

# brevis.one SMS Gateway

# Send notification to a brevis.one SMS Gateway
#
# This notification script can be put below share/check_mk/notifications.
# Please configure the needed credentials

import os
import sys
import urllib.parse
import urllib.request
import ssl


# user with permission to use Web-API of gateway
username = "xxx"
password = "xxx"
# location (http://servername/api.php)
location = "https://xxx/api.php"

to = os.environ.get("NOTIFY_CONTACTPAGER")
message = os.environ["NOTIFY_HOSTNAME"] + " "

if os.environ["NOTIFY_WHAT"] == "SERVICE":
    message += os.environ["NOTIFY_SERVICESTATE"] + " "
    message += os.environ["NOTIFY_SERVICEDESC"]
else:
    # Host message
    message += "is " + os.environ["NOTIFY_HOSTSTATE"]

url = "%s?" % location + urllib.parse.urlencode(
    [("username", username), ("password", password), ("to", to), ("text", message)]
)

# Create an SSL context that does not verify certificates
ssl_context = ssl._create_unverified_context()


try:
    handle = urllib.request.urlopen(url, context=ssl_context)
    response = handle.read().strip()

    if handle.getcode() == 200:
        sys.stdout.write("Successfully sent SMS to %s\n" % to)
    else:
        sys.stderr.write("Error sending SMS to %s: HTTP error code %s\n" % (to, handle.getcode()))
        sys.stderr.write("URL was %s\n" % url)
except Exception as e:
    sys.stderr.write("Error sending SMS to %s: %s\n" % (to, e))

It worked now :slight_smile:

But I’m still curious if, by “import certificate,” you mean the SMS server’s self-signed certificate, or not?

Which path should I copy it to? And what format (pem, cer)?

1 Like