Skip to content

Latest commit

 

History

History
85 lines (69 loc) · 2.15 KB

sensor_shell.md

File metadata and controls

85 lines (69 loc) · 2.15 KB

Shell sensor

Sensor periodically calls user's defined command. Command should provide reading in stdout either in format of parsable by strconv#ParseFloat or as a field in JSON object extractable by JSON Path query.

Shared sensor parameters are explained in sensor_shared.md file.

All config parameters for sensors are depicted in this file sensor.go with comments explaining things.

Configuration examples

  - name: echo
    type: shell
    command: 'date +%S'
    description: "Get current second executing `date` command"
    refresh_rate: 5s
    minimum: 0
    maximum: 60
    link: "https://github.com/vodolaz095/dashboard/blob/master/docs/sensor_shell.md"
    tags:
      a: b
      c: d

  - name: doSomethingScriptSensor
    type: shell
    command: '/usr/bin/do_something.sh'
    description: "Execute script every 3th minute to measure something important"
    refresh_rate: 3m
    link: "http://example.org"
    environment:
       token: 2NpRTOwsEzseYUjVUVVfw
    tags:
      a: b
      c: d

If script outputs JSON to stdout, it can be parsed using JSON Path. For example, script returns

{
   "a": 5.3,
   "b": "something",
   "d": [
      10, 11, 24
   ]
}

This $.a JSONPath query will provide 5.3 - value of a key, and this one $.d[1] will provide 11 - 2nd element of array under d key. Parameters a:10 and b: 1 will make linear transformation of reading by multiplying it by 10 and adding 1.

  - name: doSomethingScriptSensorJson
    type: shell
    command: '/usr/bin/do_something_json.sh'
    description: "Execute script every 3th minute to measure something important"
    refresh_rate: 3m
    link: "http://example.org"
    environment:
      token: 2NpRTOwsEzseYUjVUVVfw
    json_path: $.a # jsonquery allows to extract parameters from JSON from script STDOUT    
    a: 10
    b: 1
    tags:
       a: b
       c: d