What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Where do I find the script to monitor server room temperature on a budget?

Votes:

0

Where do I find the script to the blog article "How to monitor server room temperature on a budget?"

environment http-push-data-advanced python

Created on May 9, 2017 9:09:34 AM by  Torsten Lindner [Paessler Support]



17 Replies

Votes:

0

Here you'll find the according Python-script, which will send environmental data to a HTTP Push Data Advanced Sensor in your PRTG Installation from this Blog Article.

#Written for Python3
# ___ ___ _____ ___
#| _ \ _ \_   _/ __|
#|  _/   / | || (_ |
#|_| |_|_\ |_| \___|
# Environmental Monitor via RaspberryPi
# ================================
# This script will monitor environmental values in a server room, with a Raspberry PI
#
#
# Version History
# ----------------------------
# 05/05/2017    1.0      initial release
# # # # # # # # # # # # # # # # # # # # # # # # # #

import time
import requests
from envirophat import weather, light


prtg_host = 'YOUR_PRTG_PROBE_HOST'
prtg_host_port = 'HTTP_PUSH_DATA_SENSOR_PORT'
prtg_sensor_token = 'HTTP_PUSH_DATA_SENSOR_TOKEN'
interval = 60


def get_values():
    temperature = weather.temperature()
    pressure = round(weather.pressure(), 2)
    amblight = light.light()

    json_response = {
        "prtg": {
            "result": [
                {
                    "channel": "temperature",
                    "float": 1,
                    "value": temperature
                },
                {
                    "channel": "pressure",
                    "float": 1,
                    "value": pressure
                },
                {
                    "channel": "ambient light",
                    "float": 1,
                    "value": amblight
                }
            ]
        }
    }
    return json_response


try:
    while True:
        try:
            json_response = get_values()
            # print output for debugging
            # print(json_response)
            json_string = str(json_response)
            json_string = str.replace(json_string, '\'', '\"')
            prtg_request_URL = 'http://' + prtg_host + ':' + prtg_host_port + '/' + prtg_sensor_token + '?content=' + json_string
            # print(prtg_request_URL)
            request = requests.get(prtg_request_URL)
            # print(request.status_code)
        except:
            pass
        time.sleep(interval)

except KeyboardInterrupt:
    pass

Please note that our support only covers PRTG itself and the sensors that come with it out of the box. All scripts and custom sensors within our knowledge base, script world and from support are provided "as is". That means that we cannot provide assistance in modifying scripts to suit the needs/environment of the customer, as it is too time intensive for both sides.

Created on May 9, 2017 9:26:59 AM by  Torsten Lindner [Paessler Support]

Last change on May 24, 2017 7:48:41 AM by  Torsten Lindner [Paessler Support]



Votes:

0

How do you actually add this script to the Raspberry Pi?

I have a Pi with the envirophat all installed. But how do I add this script? It is a vital part of the instructions missing from these instructions;

https://blog.paessler.com/how-to-monitor-server-room-temperature-with-prtg-on-a-budget

Created on Jun 18, 2019 1:46:24 PM



Votes:

0

Copy the script to any path on the Pi and use cron to execute it every 5 minutes. That's it.

Created on Jun 19, 2019 10:52:19 AM by  Torsten Lindner [Paessler Support]



Votes:

0

Hi Sir: I use other sensors in this script example,but I have a question. Temperature and humidity values after display # not a display .c and %

Can You help me?

Thanks

Otis

Created on Jul 10, 2020 9:10:45 AM



Votes:

0

Hi,

You need to add the desired units and check that the unit is included in the xml result file.

Created on Jul 10, 2020 10:38:19 AM by  Marijan Horsky [Paessler Support]



Votes:

0

Hello,

is this also possible with a DHT22 Temperature and Humidity Sensor??

Thanks

Created on Sep 14, 2020 11:11:55 AM



Votes:

0

Hi,

This should also work with a DHT22 Temperature and Humidity sensor.

Created on Sep 15, 2020 9:18:38 AM by  Marijan Horsky [Paessler Support]



Votes:

0

Do I have to change anything when using the DHT-22 sensor instead of the envirophat?

Created on Oct 12, 2020 9:31:09 AM



Votes:

0

Did you already tested the script and checked if it works?

Created on Oct 13, 2020 8:17:00 AM by  Marijan Horsky [Paessler Support]



Votes:

0

where do i define the pin where the DTH11/DTH22 is connected on the pi?

thanks in advance

Created on Jan 8, 2021 3:21:50 PM



Votes:

0

Hi,

I have configured it to work with the DHT22 Sensor.

The Script I use looks as follows: _______________________________________________________________

import time
import requests
import board
import adafruit_dht

dht = adafruit_dht.DHT22(board.D4)

prtg_host = 'Host Probe Here'
prtg_host_port = 'Sensor Port Here'
prtg_sensor_token = 'Sensor Token Here'
interval = 10


def get_values():
    temperature = dht.temperature
    humidity = dht.humidity

    json_response = {
        "prtg": {
            "result": [
                {
                    "channel": "Temperature",
                    "float": 1,
                    "value": temperature
                },
                {
                    "channel": "Humidity",
                    "float": 1,
                    "value": humidity
                }
            ]
        }
    }
    return json_response


try:
    while True:
        try:
            json_response = get_values()
            # print output for debugging
            print(json_response)
            json_string = str(json_response)
            json_string = str.replace(json_string, '\'', '\"')
            prtg_request_URL = 'http://' + prtg_host + ':' + prtg_host_port + '/' + prtg_sensor_token + '?content=' + json_string
            print(prtg_request_URL)
            request = requests.get(prtg_request_URL)
            print(request.status_code)
        except:
            pass
        time.sleep(interval)

except KeyboardInterrupt:
    pass

______________________________________________________________

The only thing thats left to do now is to encrypt the data with HTTPS. Can someone explain how to do this or do you need to use a different sensor in PRTG for this?

I have looked into the HTTP IoT Push Data Advanced Sensor since it uses HTTPS at default, but Im not Sure how to send my Data to this Sensor. When I change the port and token numbers the data does not arrive. How do I setup my Raspberry Pi to push out the Data using HTTPS instead of HTTP?

Any help would be greatly appreciated.

Thanks in advance

Created on Apr 8, 2021 8:37:53 AM

Last change on Apr 8, 2021 8:43:13 AM by  Felix Wiesneth [Paessler Support]



Votes:

0

I am also searching for a solution for the new pimoroni enviro (not the envirophat anymore because it was discontinued). Trying to write a Python script to get everything to work but I'm new to python, so I'm having some trouble. If anyone has a solution for this configuration I would be greatful if you would like to share.

Created on Apr 8, 2021 1:26:52 PM



Votes:

0

I ran into this issue and I figured I would share the code I slapped together.

#Written for Python3
# ___ ___ _____ ___
#| _ \ _ \_   _/ __|
#|  _/   / | || (_ |
#|_| |_|_\ |_| \___|
# Environmental Monitor via RaspberryPi+ enviroplus
# ================================
# This script will monitor environmental values in a server room, with a Raspberry PI
#
#
# Version History
# ----------------------------
# 05/05/2017    1.0      initial release
# 12/15/2021    1.5      Modified for EnviroPlus - without gas sensor
# # # # # # # # # # # # # # # # # # # # # # # # # #

import time
import requests
#from envirophat import weather, light
from bme280 import BME280
import json
try:
    # Transitional fix for breaking change in LTR559
    from ltr559 import LTR559
    ltr559 = LTR559()
except ImportError:
    import ltr559
try:
    from smbus2 import SMBus
except ImportError:
    from smbus import SMBus

bus = SMBus(1)
bme280 = BME280(i2c_dev=bus) # BME280 temperature, humidity and pressure sensor




prtg_host = '10.0.10.2'
prtg_host_port = '5050'
prtg_sensor_token = '337692AF-FA7A-461C-9C31-E90580B9025B'
interval = 60


def get_values():
    temperature = bme280.get_temperature()
    humidity = bme280.get_humidity()
    pressure = bme280.get_pressure()
    amblight = ltr559.get_lux()

    json_response = {
        "prtg": {
            "result": [
                {
                    "channel": "temperature",
                    "float": 1,
                    "value": temperature
                },
                {
                    "channel": "humidity",
                    "float": 1,
                    "value": humidity
                },
                {
                    "channel": "pressure",
                    "float": 1,
                    "value": pressure
                },
                {
                    "channel": "ambient light",
                    "float": 1,
                    "value": amblight
                }
            ]
        }
    }
    return json_response


try:
    while True:
        try:
            json_response = get_values()
            # print output for debugging
            # print(json_response)
            json_string = str(json_response)
            json_string = str.replace(json_string, '\'', '\"')
            prtg_request_URL = 'http://' + prtg_host + ':' + prtg_host_port + '/' + prtg_sensor_token + '?content=' + json_string
            # print(prtg_request_URL)
            request = requests.get(prtg_request_URL)
            # print(request.status_code)
        except:
            pass
        time.sleep(interval)

except KeyboardInterrupt:
    pass


Created on Dec 16, 2021 12:48:08 AM



Votes:

0

Hey @paul Wilson - when I try to run your updated script I get a lot of "import: command not found" error messages.

I haven't entered any PRTG info to the script as listed in lines 39-42 as I'm just trying to test the script and make sure it works.

Created on Dec 27, 2021 3:23:37 PM



Votes:

0

Hello Paul,

Thank you for your message.

Maybe Paul can provide further help here however according to your message the modules seem not to be installed in your environment. If it/they can't be installed via pip, you will probably need to download and import the missing librairie(s) manually in your project.

Regards.

Created on Dec 28, 2021 6:21:04 AM by  Florian Lesage [Paessler Support]



Votes:

0

Hi all!

I have succesfully set up my Raspberry Pi in PRTG (I get valid pings), and have used the script here but modified to the Adafruit BME280.

The url is formed (correctly, I assume, but am not entirely sure) but, I don't get the request status code returned when asking to print it. Needless to say, I don't register anything in PRTG either.

I have double checked the probe IP and the ID token.

Has anyone experienced similar?

Thanks in advance!

Created on Feb 18, 2022 9:17:27 AM



Votes:

0

Hi Rikke,

Thank you for your message.

To help you investigating on the issue, I invite you to execute the same POST request from the raspberry pi by using CURL as well as from an other device which also has access to the probe on which the sensor is running. That way, you can check if the sensor is running properly and pinpoint the origin of the issue.

In case you do not get data in the sensor, I invite you to execute a manual scan and then try again (with the operations above). Make sure that the probe service is listening on the port you defined by using netstat for example.

Finally, can you share the JSON output as well so we can verify if it is valid or not.

Regards.

Created on Feb 23, 2022 7:22:21 AM by  Florian Lesage [Paessler Support]

Last change on Feb 23, 2022 7:23:07 AM by  Florian Lesage [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.