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 ...
    • Disable alerts for a plugin if the parent server is down

      If a plugin monitor's parent server goes down, you can choose to exclude additional alerts from the plugin monitor. This way, you won’t receive alerts when the plugin monitor goes down as a result of the parent server being unavailable. To enable ...