As a product manager at Plesk, I am always interested in how our products work to gain an in-depth understanding of the tools we’re handing out to our customers. That’s why after the release of 360 Monitoring, I used the tool to build customized dashboards with full server and site monitoring including all pertinent information available by default on the platform.
However, I realized I was missing something: as a user of the Plesk WP Toolkit, I’m accustomed to enjoying an overview of all my WordPress Websites and what their status is according to the Toolkit. So I decided to integrate the toolkit into my 360 Monitoring platform by writing my own plugin!
Interested in integrating your favorite tools into your 360 Monitoring dashboards? Then take a look at how I got started so that you can write your own 360 Monitoring plugins too!
The basics of 360 Monitoring Plugins
In the documentation provided for the 360 Cloud Platform, you’ll find a dedicated article on how 360 Monitoring plugins work and how to build them, but in this post, we’re going to look at the process in action.
After understanding how the plugins work and how to leverage CLI calls inside the plugins, the next step of my journey continues towards the Plesk command-line interface to take a closer look at the WP Toolkit capabilities.
The WP Toolkit CLI
Using the Plesk command-line interface, you can easily get a list of all WordPress installations managed with the WP Toolkit using this command:
plesk ext wp-toolkit -l
After executing this, the command returned the list that I was able to filter, piping the right information into the variables. But what does this mean specifically? Let’s take a closer look.
My plugin code
Beyond the theory, here we’re taking a look at the real code extracted in the previous step, along with an explanation:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import plugins
class Plugin(plugins.BasePlugin):
__name__ = ‘plesk-wpt’
def run(self, config):
”’
Grabbing some basic information from the plesk server add to /etc/sudoers the following line:
agent360 ALL=(ALL) NOPASSWD: /usr/sbin/plesk
test by running:
sudo -u agent360 agent360 test plesk-wpt
Add to /etc/agent360.ini:
[plesk-wpt]
enabled = yes
interval = 600
”’
data = {}
data[‘wpsites’] = int(os.popen(‘sudo -n plesk ext wp-toolkit –list | grep -$
data[‘wpsites-live’] = int(os.popen(‘sudo -n plesk ext wp-toolkit –list | g$
data[‘wpsites-outdated’] = int(os.popen(‘sudo -n plesk ext wp-toolkit –list$
data[‘wpsites-outdated-php’] = int(os.popen(‘sudo -n plesk ext wp-toolkit –$
data[‘wpsites-broken’] = int(os.popen(‘sudo -n plesk ext wp-toolkit –list |$
return data
if __name__ == ‘__main__’:
Plugin().execute()
Here’s the steps I took in more detail:
- First, I created a new array in which I can store my data.
- From there, I filled up the array with various integers I grabbed from the command line interface of Plesk and the WP Toolkit.
- Last but not least, I returned the data to be collected by the monitoring agent.
How to use & install your plugin
First, you need to find out the location where your 360 Monitoring plugins are currently installed. To do so, simply execute the following code:
agent360 info
Example output:
Version: 1.2.33
Plugins enabled: ping, apt-updates, system, iostat, httpd, loadavg, memory, mysql, nginx, diskusage, network, process, docker, cpu, swap
Plugins directory: /usr/local/lib/python3.7/dist-packages/agent360/plugins
Server: 12354148123124
As described in the documentation for the plugins, it will now tell you the exact location. Next up, for my plugin I need to create a file, which I have named plesk-wpt.py in the given folder (i.e. in the location discovered in the previous step).
Now simply open the file, paste the code and save it.
Before testing, we need to make sure the user agent360 is allowed to access the Plesk command line with sudo and without password. Therefore we’re adding the following line to /etc/sudoers:
agent360 ALL=(ALL) NOPASSWD: /usr/sbin/plesk
To verify the plugin is installed and all data can be fetched, run this code:
sudo -u agent360 agent360 test plesk-wpt
Now you should get an output with the actual data. To finally activate the plugin and make sure the data is reported in the 360 Monitoring infrastructure, we need to add the following lines to /etc/agent360.ini:
[plesk-wpt]
enabled = yes
interval = 600
This configuration tells the agent360 not only to start using the plugin but to report the status every 600 seconds.
Once done, restart the monitoring service:
service agent360 restart
Verify the data
After a few minutes, you should be able to see a new tab in the detailed view of your server on monitoring.platform360.io named “plesk-wpt” – the name assigned to your plugin folder. All data will be shown there in graphs and you can now start to add alerts or metrics based on this data.
Conclusion
It’s as easy as that! And since agent360 is open source, you are also free to discover all the other monitoring plugins on our GitHub page.
Have you built an interesting plugin yourself? Send us a push and maybe we will include it in our next release!