Monitoring directory contents

With item pre-processing added to LLD workflow and new javascript pre-processing step, it’s possible to monitor a directory for its file changes.

The trick is to use javascript pre-preprocessing step to convert file list to LLD format. The file list can be obtained with system.run key (requires enabled EnableRemoteCommands parameter in agent configuration file) or by user parameter (the UserParameter parameters in agent configuration file).

Create a discovery rule based on system.run key:

system.run[find /etc/* -maxdepth 0 -type f]

Add javascript preprocessing step to convert the file list into Zabbix low level discovery data:

var lld = [];
var lines = value.split("\n");
var lines_num = lines.length;
for (i = 0; i < lines_num; i++)
{
  var row = {};
  row["{#FILE}"] = lines[i]
  lld.push(row);
}
return JSON.stringify(lld);

The script takes file list and command output and converts it into JSON format:

[
  {
    "{#FILE}": "<full path to file>"
  },
  {
    "{#FILE}": "<full path to file>"
  }
]

Add item prototype to monitor checksums:

 

And finally, the trigger to generate events:

Avatar

Author: Andris Zeila

Developer at Zabbix.

Leave a Reply