Foglight offers the capability to add custom script agents for any type of data collection. This can be a shell scripts or batch files. It is one possibility to add custom functionality to the monitoring. It can be done by using the script agent builder under “Foglight UI | Administration |Tooling”.

Unfortunately the Script Agent Builder does not provide to pass parameters to the script by using agent ASPs (Agent Startup Parameter) in the properties. This issue can be solved by using the Cartridge Builder.

The Cartridge Builder can be found under the “Development Tools” menu.

Prerequisites to work with the cartridge builder are:

  • the Foglight user must have the “Cartridge Developer” role
  • the cartridge builder cartridge was loaded into Foglight. It can be found in the cartridges directory of the Foglight installation or can be downloaded from the Quest support page.

Note 1: Cartridge builder can be downloaded from support site | Product Downloads section | Under Utilities

This cartridge can be installed on to Foglight from the Cartridges UI

Note 2: The user will need to be added the Cartridge Developer role

The following example shows of how to use the cartridge builder to pass parameters to a custom script agent.

The script below counts the number files in up to three directories ($1,$2,$3) expecting the directory names as parameters.

#!/bin/bash
array=($1 $2 $3)
element_count=${#array[*]}
x=0
y=1
echo TABLE filecount1
while [ $y -le $element_count ];
do

  cd ${array[$x]}
  echo START_SAMPLE_PERIOD
  echo name.String.Id=${array[$x]}
  echo filecount:count=`find . -type f | wc -l`
  echo NEXT_SAMPLE
  x=`expr $x + 1`
  y=`expr $y + 1`
done

echo END_SAMPLE_PERIOD
echo END_TABLE

The script contains some echo commands that are necessary to integrate it into Foglight.

echo TABLE filecount1                  -> Foglight will create a table called filecount1 to save the collected
                                                              values.
echo START_SAMPLE_PERIOD   -> Start of the collection
echo name.String.Id                       -> the column “name” will be created in table filecount1 and filled
                                                              with the directory names. String.Id means that the directory name
                                                              will be used for grouping because it is not changing.

echo filecount:count                      -> additional column to save the count value

echo NEXT_SAMPLE                     -> next sample used in a loop
echo END_SAMPLE_PERIOD       -> end of sample
echo END_TABLE                          -> close the table filecount1

Executing the script with three directories as parameters will create the following output:

[markus@docker scripts]$ ./countfiles1.sh /opt/Foglight /opt/Foglight/bin /opt/Foglight/scripts

TABLE filecount1
START_SAMPLE_PERIOD
name.String.Id=/opt/Foglight
filecount:count=22535
NEXT_SAMPLE

START_SAMPLE_PERIOD
name.String.Id=/opt/Foglight/bin
filecount:count=18
NEXT_SAMPLE

START_SAMPLE_PERIOD
name.String.Id=/opt/Foglight/scripts
filecount:count=26
NEXT_SAMPLE
END_SAMPLE_PERIOD
END_TABLE

The above script will be used as a custom script agent in this example where the directory names will be entered as parameters.

There is one additional adjustment necessary before the script is able to receive parameters in Foglight. The definition of script parameters require names that can be referenced. The names must be entered in the script before we load it into Foglight. In the example $1, $2 and $3 will be renamed to $Verzeichnis1, $Verzeichnis2 and $Verzeichnis3. The names will later be referenced by ASPs. The script should then look like this:

#!/bin/bash
array=($Verzeichnis1 $Verzeichnis2 $Verzeichnis3)
element_count=${#array[*]}
x=0
y=1
echo TABLE filecount1
while [ $y -le $element_count ];
do

  cd ${array[$x]}
  echo START_SAMPLE_PERIOD
  echo name.String.Id=${array[$x]}
  echo filecount:count=`find . -type f | wc -l`
  echo NEXT_SAMPLE
  x=`expr $x + 1`
  y=`expr $y + 1`
done

echo END_SAMPLE_PERIOD
echo END_TABLE

Now click on „Cartridge Builder“ and the below dashboard will show up:

The following steps will demonstrate how to create a cartridge from the script above and define parameters for the directory names that can be passed over ASPs:

  1. Click ”Create“ in the upper left and enter the cartridge name the author and comments. Then click „“Create“.



  2. A row for the new cartridge shows up. Click on the agent name or the „Edit“ pen on the right side.



  3. On the next Dashboard click on „Add Elements“ and select „add New Agent“. As you can see also rules, dashboards etc. can be added to the custom cartridge if necessary.



  4. Type in an agent name and click „Create“



  5. On the right side of the Dashboards under „Cartridge Definition” the new Agent with the name "filecount" will become visible. Click on the agent and select „edit“.



  6. Now upload the script that was prepared for the use in Foglight. Under „Agent Files“ click „Upload File“



  7. Select the prepared shell script and click „Upload“.



  8. Mark the uploaded file and click „Set Main Command“.



  9. The next step is to define the parameters (ASPs) to pass to the script. In the example with the names Verzeichnis1, Verzeichnis2 and Verzeichnis3. Change to the tab „Agent Properties“ and click „Edit“.



  10. Create a parameter group by clicking on „Add Group“and add a goup name. In this example we choose the name „Verzeichnisse“.

          


  11. By clicking on the + button in the group row the parameters that we ned for the script can be defined. In this case 3 parameters for the directories (Verzeichnisse) as String. This can be done by clicking on Probs. ID and Label should match the parameter name in the script. Verzeichnis1, Verzeichnis2 and Verzeichnis3. Length of the Strings, if it is optional etc. can be set here. At the end click “Save“.




  12. After everything is ready click on „Cartridge Editor“ to return to the Cartridge Editor.



  13. Click on „Generate CAR File“ to generate the cartridge that can be imported in Foglight.



  14. There are two symbols at the end of the cartridgefile row. The first one let you save the CAR file. The CAR file contains all configurations and the uploaded script. It is portable and can be imported in other Foglight installations. The second button loads the cartridge directly into current Foglight system.

The cartridge is ready and can be deployed to agent managers. Agents from the type "filecount" can now be created and configured like any other Foglight agent. The configuration of the agent properties offers our three input parameters Verzeichnis1, Verzeichnis2 and Verzeichnis3, up to three directories where it should count the number of files. Dashboards, rules etc. can be prepared and added to the cartridge by repeating the above step.

Visualize the data and rules

To visualize the collected in a “drag and drop” dashboard, the values of the collection are available under e.g. “Administration/Management Server/All Agents/Agentname” in the Foglight Classic View under the “Data” tab.

           

To create a dashboard in WCF a UI query can be used to reference the values to use it in e.g., a row-oriented table.

UI Query “FileCountTest” to get the data of the example by referencing the “filecount_Agent_Table”



Example usage of the “FileCountTest” UI query to create a row oriented table



Example for a rule with the condition “file count > 60” to create alarms for the custom script agent

Anonymous
Related Content