Room temperature alert

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Post Reply
mandar18
Posts: 31
Joined: Thu Feb 08, 2024 6:43 am

Room temperature alert

Post by mandar18 »

Hello Team,
Need to set a room temperature alert for my server room, I don't know which plugin needs to be installed, I am using the following devices Ubibot GS1-AETH1RS + TH30S-B Ethernet Thermometer Hygrometer, WiFi Temperature Humidity Sensor, Digital Temperature Data Logger.
It is a cloud-based device, so we don’t have an IP address to query. You will need to use the URL to find something that can read the results of an API call.
Can you please help me out?
Do I need to make changes in the command file also?

Note-We won't be having IP address only the link we will be having
bbahn
Posts: 380
Joined: Thu Jan 12, 2023 5:42 pm

Re: Room temperature alert

Post by bbahn »

Hello @mandar18,

It sounds like you're looking for a custom plugin that will query your URL and read the response. Is this correct?

I would suggest creating a script that uses Python, Bash or some other language compatible with your Nagios Core instance that will query the desired URL and based on the response, give the appropriate output.

Here are some resources to help you get started:
Nagios Plugins - Developer Guidelines
Nagios Plugins - Developer Guidelines - Plugin Outputs
Actively advancing awesome answers with ardent alliteration, aptly addressing all ambiguities. Amplify your acumen and avail our amicable assistance. Eagerly awaiting your astute assessments of our advice.
mandar18
Posts: 31
Joined: Thu Feb 08, 2024 6:43 am

Re: Room temperature alert

Post by mandar18 »

But by URL, can we monitor the room's temperature using the plugin?

Also can we fetch results from API?
I want to monitor the "https://webapi.ubibot.com/channels/8933 ... b547f13f39" this link.
kg2857
Posts: 490
Joined: Wed Apr 12, 2023 5:48 pm

Re: Room temperature alert

Post by kg2857 »

Ask yourself how you would pull this info from the shell. Then do it. Then create a small script that does it and returns text and a return value.
Of course someone else has possibly done the same thing so check out the exchange.
mandar18
Posts: 31
Joined: Thu Feb 08, 2024 6:43 am

Re: Room temperature alert

Post by mandar18 »

@Bbahn can you please help on this?
I am not getting the exact path what you are saying.
bbahn
Posts: 380
Joined: Thu Jan 12, 2023 5:42 pm

Re: Room temperature alert

Post by bbahn »

Hello @mandar18,

I threw together a quick python script to get you started:

Code: Select all

import requests
import json

def get_data():
    url = "https://webapi.ubibot.com/channels/89336?account_key=7bc1cdc6599832d23e4214b547f13f39"
    response = requests.get(url)
    data = response.json()
    return data

data = get_data()

# "field1": "Temperature",
# "field2": "Humidity",
# "field3": "Voltage",
# "field4": "WIFI RSSI",
# "field5": "GSM RSSI",
# "field6": "Light",
# "field7": "RS485 Temperature",
# "field8": "RS485 Humidity",
# "field9": "RS485 Soil Temperature",
# "field10": "RS485 Soil Moisture",
# "field11": "External Light",
# "field12": "PT100 Temperature",
# "field13": "Wind Speed",
# "field14": "Carbon Dioxide",
# "field15": "RS485 Atmospheric Pressure",


def parse_data(data):
    last_values = data["channel"]['last_values']
    last_values = json.loads(last_values)
    field1 = last_values['field1']['value']
    field2 = last_values['field2']['value']
    field3 = last_values['field3']['value']
    field6 = last_values['field6']['value']
    return field1, field2, field3, field6

field1, field2, field3, field6 = parse_data(data)
print("Temperature: ", field1)
print("Humidity: ", field2)
print("Voltage: ", field3)
print("Light: ", field6)
print()
Now you just need to take this data, handle the intervals and output status. You can reference other Nagios python plugins as reference as well as use the documentation I mentioned before.
Actively advancing awesome answers with ardent alliteration, aptly addressing all ambiguities. Amplify your acumen and avail our amicable assistance. Eagerly awaiting your astute assessments of our advice.
mandar18
Posts: 31
Joined: Thu Feb 08, 2024 6:43 am

Re: Room temperature alert

Post by mandar18 »

Thank you Bbahan,
I need to add the host first to get data, but like I said before, I only have an API link where I can get the data.
what needs to be done now to add the same as a host in Nagios core?
For example, I am using the below stuff to add a host
define host{
use generic-host
host_name XXXX
alias XXX
address 192.168.XX.XX
check_command check-host-alive
max_check_attempts 5
notification_interval 60
notification_period 24x7
notification_options d,u,r
contact_groups admins
}

To Add the API If I don't have an IP Address then how do I add that API to the host?
mandar18
Posts: 31
Joined: Thu Feb 08, 2024 6:43 am

Re: Room temperature alert

Post by mandar18 »

@Bbahan,
Can you please help me ?
bbahn
Posts: 380
Joined: Thu Jan 12, 2023 5:42 pm

Re: Room temperature alert

Post by bbahn »

You will want command and host or service definitions to be something like the following:

Code: Select all

define command{
	name		        check_temperature
	command_name		check_temperature
	command_line	        $USER1$/check_temperature -I $HOSTADDRESS$ $ARG1$
}

Code: Select all

define service{
	use		  	generic-service		; Inherit default values from a template
	host_name		Ubibot GS1-AETH1RS
	service_description	Temperature
	check_command		check_temperature
}
Where check_temperature is the name of your plugin located in /user/local/nagios/libexec

You can find out more about Nagios Core definitions here: Nagios Core Documentation - Object Definitions
Actively advancing awesome answers with ardent alliteration, aptly addressing all ambiguities. Amplify your acumen and avail our amicable assistance. Eagerly awaiting your astute assessments of our advice.
Post Reply