How to create a free chatbot to access your PRTG server status with Facebook Messenger in 15 minutes

Within just a few minutes you can create a very simple and free chatbot for Facebook Messenger that is able to access your monitoring status from your PRTG. In this blog article I will use the ChatFuel service (www.chatfuel.com) to create such a chatbot, and connect it to my PRTG server.

PRTG MONITORS YOUR NETWORK 24/7 TO TIMELY ALERT YOU TO ISSUES BEFORE THEY BECOME EMERGENCIES.

What’s a Facebook chatbot? A Facebook bot is an extension to your Facebook Page’s messaging functionality. Each Facebook bot has to be linked with an existing Facebook Page. So if anyone is chatting with your bot, they’re chatting with your Facebook Page — but instead of talking human-to-human, your bot talks for you.

Try Dirk’s PRTG Bot

You can connect to my PRTG bot (it won’t show you sensitive information, of course) here:

messenger_code_235083633613588

Simple click this link https://m.me/dirk.paessler.blog or scan the code above with your messenger app. It will welcome you like this:

chatbog2

Now you can click one of the buttons or ask questions or enter commands. For example “status” returns:

Just a second, I’ll get you the status right now….
Here is the status of your network:
1223 sensors are up and running!
8x alarm and 13x ack’ed alarm
0x unusual and 9x warning
14x paused and 3x unknown

You can even find out how our office is doing with “business”:

In the Paessler office it’s 21,0 °C.
Global average request time for http://www.paessler.com is 338 msec.

How does it work?

Please remember that the page and your chatbot will be publicly visible. The setup below does not include login/authentication, this will come later, the bot is hard wired to a dedicated read-only account in my PRTG server.

The ChatFuel website walks you through the whole process pretty well. Go to https://chatfuel.com and click “Create a free Facebook Bot”. Unless you are having more than 100.000 conversations per month the service is free (!).

gs_botcreate_01-1

You will need to sign in with your Facebook login, and then you need to set up a page.

In the following, I will only explain the PRTG-oriented integration. Please follow the instructions of ChatFuel to create your bot.

Integrating ChatFuel with your PRTG Server

For security reasons I have created a dedicated read-only-account on my PRTG server and gave it read-only-access to the root group (so it can see all sensors). You need the login name of this account and the passhash (you can find that in the user account settings page).

Then I created a new JSON API “block” (as it is called in ChatFuel):

chatfuel1

As you can see I entered an API-based URL if my PRTG server.

https://myprtgserver.com/api/chatfuel.htm?username=**YOURACCOUNT**&passhash=**YOURHASH**&id=0

This API file is not a default file of PRTG, I created it myself. This is the content of the file:

{
 "messages": [
 {"text": "Here is the status of your network:"},
 {"text": "<#objectstatus name="upsens" show="textraw"> sensors are up and running!"},
 {"text": "<#objectstatus name="downsens" show="textraw">x alarm and <#objectstatus name="downacksens" show="textraw">x ack'ed alarm"},
 {"text": "<#objectstatus name="unusualsens" show="textraw">x unusual and <#objectstatus name="warnsens" show="textraw">x warning"},
 {"text": "<#objectstatus name="pausedsens" show="textraw">x paused and <#objectstatus name="undefinedsens" show="textraw">x unknown"}
 ]
}

I named the file “chatfuel.htm” and placed it into the \webroot\api folder of my PRTG server.

And that’s it. As soon as this json content block is triggered by your chatbot you will get the current status.

My second file displays values and status for two sensors (our room temperature and the average value of a Cloud http sensor. This is the API file:

{
 "messages": [
 {"text": "At the PHQ office it's <#objectstatus id="27397" name="lastvalue" show="text">."},
 {"text": "Global average request time for www.paessler.com is <#objectstatus id="27637" name="lastvalue" show="text">."} ]
}

All you need are the sensor-ids of the sensor that you want to display, you can change the text as you want, and you can add more lines, too.

Always remember that all we have done here is PUBLIC, there is not authentication or login, so you need to put some consideration in what information you make accessible with your bot.

Using user variables the next level would be to enter login credentials (they are stored by ChatFuel on a by-chat-account level) so each user could see only his/her sensors.

PS: If you like how we think about IT and networks, check out our software PRTG Network Monitor which monitors uptime, usage, and performance of networks.

Author: Dirk Paessler

Founder and CEO, Paessler AG

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s