Sample Shell plugin script with jq library

Sample Shell plugin script with jq library


#!/bin/bash

# Pre-requisites: jq library to run
# ubuntu: sudo apt-get install jq

##### Site24x7 Configuration Constants #####
PLUGIN_VERSION=1
HEARTBEAT_REQUIRED=true

##### Plugin Input Constants #####
DIRNAME=.
SEARCH_LEVEL=1

##### Plugin Code #####
DATA='{}'

DATA=$( echo $DATA | jq '. + {"plugin_version": "'$PLUGIN_VERSION'"}') 
DATA=$( echo $DATA | jq '. + {"heartbeat_required": "'$HEARTBEAT_REQUIRED'"}') 

##### Plugin Logic to get the number of files and directories
FILES=`find $DIRNAME -maxdepth $SEARCH_LEVEL -type f | wc -l`
DIRS=`find $DIRNAME/* -maxdepth $SEARCH_LEVEL -type d | wc -l`


##### Add Key and value to be monitored
##### Replace the sample keys with the metrics you want to monitor
##### Execute the commands and store the values in a variable
##### Replace the dummy values with the variables to monitor
DATA=$( echo $DATA | jq '. + {"file_count": '$FILES'}') 
DATA=$( echo $DATA | jq '. + {"dir_count": '$DIRS'}') 

##### Add the units for the values to be monitored #####
DATA=$( echo $DATA | jq '. + {"units": {} }') 

##### Remove if not required
DATA=$( echo $DATA | jq '.units.file_count = "count"') 
DATA=$( echo $DATA | jq '.units.dir_count = "count"') 

##### Print the data
echo $DATA  | jq '.'





    • Related Articles

    • How to increase the Script Execution Timeout value for plugins

      If a plugin's script execution time exceeds the Script Execution Timeout value configured in Site24x7, it could result in errors during plugin installation or disrupt the polling for existing plugin monitors. In such cases, you need to extend the ...
    • How to troubleshoot my Windows PowerShell Plugin?

      By default, the Site24x7 monitoring Windows agent will run as a SYSTEM user. In case, if you would like to verify if the plugin script is giving the output properly as SYSTEM user, follow these steps: Download PsExec from this link and extract the ...
    • How do I add the Dell iDRAC plugin for Windows?

      Prerequisites Install the latest version of the Net-SNMP package. Follow these steps to install and configure it. Install Python 3.6. Plugin Installation Create a folder named idrac. Download the files from our GitHub repository and place them in the ...
    • Install and configure an Oracle plugin in Windows

      Prerequisites Ensure that the Site24x7 Windows server monitoring agent is installed in the system where the Oracle instance is running. Ensure python3 is installed in the system and add it to the Windows path. Refer to the link below for adding ...
    • Troubleshoot the "pymysql module not found" error when installing the MySQL plugin

      If you're encountering the pymysql module not found error, it likely means that the pymysql Python library is not installed on the server. pymysql is a Python package that provides a way to interact with MySQL databases using Python code and is used ...