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.
300.000 administrators have chosen PRTG to monitor their network. 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]



12 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)



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.