What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

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

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  chris11122 (0)



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  otisou (0)



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

Hello,

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

Thanks

Created on Sep 14, 2020 11:11:55 AM by  mrtrustworthy (0)



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  mrtrustworthy (0)



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  brokentropia (0)



Votes:

0

Your Vote:

Up

Down

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 by  mrtrustworthy (0)

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



Votes:

0

Your Vote:

Up

Down

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 by  rsw (0)



Votes:

0

Your Vote:

Up

Down

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 by  paul Wilson (0)



Votes:

0

Your Vote:

Up

Down

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 by  sairdouble (0)



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  Rikke (0)



Votes:

0

Your Vote:

Up

Down

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]



Please log in or register to enter your reply.


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.