Adding a new plug object to nAttrMon

In nAttrMon you have input, output and validation plugs. Althought theses plugs can have their own code the best pratice is to use the input, output and validation plug definition to use a specific existing object plug and then simply provide the necessary arguments. For example, to run a command and use the output as a monitoring metric you just need to define an input plug like this:

input:
  name    : Number of files in /tmp
  execFrom: nInput_Shell
  execArgs:
    attrTemplate: Metrics/Number of files in tmp
    cmd         : |
      find /tmp | wc -l | tr -d '\n'
    jsonParse   : false

And you can quickly test it using the provided nAttrMon_single.yaml.sample and replacing the sample input with this one. Executing you will get:

$ ojob test.yaml
[...]
VAL | (name: 'Metrics/Number of files in tmp', val: '18', date: 2021-01-02/03:04:05.678)
[...]

You just used the nInput_Shell object with the arguments attrTemplate, cmd and jsonParse. nAttrMon comes with generic objects and more can also be added (check the nAttrMon configs project).

So how do you build an object?

Building a nInput object

Let’s take an example and build a nInput object to retrieve details about HTTPs SSL certificates. Every HTTPs site as a SSL certificate and they come with a start and end date. Once the end date is reached the SSL certificate becomes invalid and browsers will prompt users an error whenever they try to access the site.

The simplest way to start is by using the provided util/templates/Object_nInput_template.js code. Copy it to your config/objects folder and rename it appropriately.

Using the template

Using the sample code provided in the OpenAF “Check SSL Certificates” guide lets build a simple nInput_SSLCerts objects.

  1. Create a nInput_SSLCerts.js files on a config/objects folder
  2. Copy the code from util/templates/Object_nInput_template.js
  3. Rename all occurrences of nInput_SomeObject by nInput_SSLCerts

Define the input arguments

For our sample we want to be able to provide the site URL or address and port.

Building a nOutput object

tbc