42ity / fty-sensor-gpio

Agent to manage GPIO sensors and devices
Other
0 stars 9 forks source link

fty-sensor-gpio

fty-sensor-gpio is an agent to manage GPI sensors and GPO devices. It is able to read status of any kind of GPIO devices or set (enable / disable) any GPO.

GPIO devices are basic dry-contact, which are either 'opened' or 'closed', to indicate a status or enable / disable a device.

How to build

To build fty-sensor-gpio project run:

mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=usr -DBUILD_TESTING=On ..
make
sudo make install

Optionally, to run fty-outage tests run:

make test

How to run

To run fty-sensor-gpio project:

./src/fty-sensor-gpio

For the other options available, refer to the manual page of fty-sensor-gpio

systemctl start fty-sensor-gpio

Configuration file and request

To configure fty-sensor-gpio, a configuration file exists: fty-sensor-gpio.cfg

Beside from the standard configuration directives, under the server and malamute sections, hardware capabilities are requested to the fty-info agents, to adapt to the behavior of fty-sensor-gpio, using:

This answer will allow to get:

Commissioning using CSV file

It is possible to declare GPIO sensors through the CSV file. The following fields and extended attributes are available:

Example of entries:

name,type,sub_type,parent_name.1,status,priority,model,port,normal_state,logical_asset,gpo_powersource
GPIO-Sensor-Door1,device,sensorgpio,IPC1,active,P1,DCS001,1,opened,Rack1,
GPIO-Sensor-Smoke1,device,sensorgpio,IPC1,active,P1,DCS001,1,opened,Room1,1
GPIO-Beacon1,device,sensorgpio,IPC1,active,P1,GPOGEN,2,,Room1,

In the above example, we have:

Architecture

Overview

fty-sensor-gpio is composed of 3 actors:

Template files

Template files describe a GPIO sensor, and provide default values (such as 'normal-state') in case the user does not provide it through the commissioning.

Warning: Template files are mandatory! If there is no template file for a commissioned sensor, this sensor will not be monitored!

Template files are provided in the 'src/selftest-ro/data/' directory of the source tree, and installed by default to '/usr/share/fty-sensor-gpio/data/'.

Template files are named using the 'part-number' field, with the '.tpl' (template) file extension, and have the following format:

manufacturer   = <value>
part-number    = <value>
type           = <value>
normal-state   = <value>
gpx-direction  = <value>
power-source   = <value>
alarm-severity = <value>
alarm-message  = <value>

For example:

manufacturer   = Eaton
part-number    = DCS001
type           = door-contact-sensor
normal-state   = closed
gpx-direction  = GPI
power-source   = external
alarm-severity = WARNING
alarm-message  = Door has been $status

'power-source' allows to specify if a sensor is:

'alarm-message' can be adapted at runtime through the use of some variables, to adapt the alert message:

Protocols

Published metrics

Metrics are published on the '_METRICS_SENSOR' stream.

For example:

stream=_METRICS_SENSOR
sender=fty-sensor-gpio
subject=status.GPI2@sensorgpio-90
D: 13-01-28 10:22:53 FTY_PROTO_METRIC:
D: 13-01-28 10:22:53     aux=
D: 13-01-28 10:22:53         port=GPI2
D: 13-01-28 10:22:53     time=1359368573
D: 13-01-28 10:22:53     ttl=300
D: 13-01-28 10:22:53     type='status.GPI2'
D: 13-01-28 10:22:53     name='sensor-90'
D: 13-01-28 10:22:53     value='opened'
D: 13-01-28 10:22:53     unit=''

Published alerts

Alerts are published on the '_ALERTS_SYS' stream.

Alarm messages:

Example of alert message:

stream=_ALERTS_SYS
sender=fty-alert-flexible
subject=door-contact.state-change@sensorgpio-19/WARNING@sensorgpio-19
D: 17-09-04 08:23:49 FTY_PROTO_ALERT:
D: 17-09-04 08:23:49     aux=
D: 17-09-04 08:23:49     time=1504513429
D: 17-09-04 08:23:49     ttl=750
D: 17-09-04 08:23:49     rule='door-contact.state-change@sensorgpio-19'
D: 17-09-04 08:23:49     name='sensorgpio-19'
D: 17-09-04 08:23:49     state='ACTIVE'
D: 17-09-04 08:23:49     severity='WARNING'
D: 17-09-04 08:23:49     description='Door to Rack01 is opened. Reported '
D: 17-09-04 08:23:49     action='EMAIL'

Mailbox requests

It is possible to request the agent GPIO for:

Action on GPO sensors

The USER peer sends the following messages using MAILBOX SEND to FTY-SENSOR-GPIO-AGENT ("fty-sensor-gpio") peer:

where

The FTY-SENSOR-GPIO-AGENT peer MUST respond with one of the messages back to USER peer using MAILBOX SEND.

where

Detailed manifest of supported sensors

The USER peer sends the following messages using MAILBOX SEND to FTY-SENSOR-GPIO-AGENT ("fty-sensor-gpio") peer:

where

The FTY-SENSOR-GPIO-AGENT peer MUST respond with one of the messages back to USER peer using MAILBOX SEND.

where

Summary manifest of supported sensors

The USER peer sends the following messages using MAILBOX SEND to FTY-SENSOR-GPIO-AGENT ("fty-sensor-gpio") peer:

where

The FTY-SENSOR-GPIO-AGENT peer MUST respond with one of the messages back to USER peer using MAILBOX SEND.

where

Create a new sensor template file

The USER peer sends the following messages using MAILBOX SEND to FTY-SENSOR-GPIO-AGENT ("fty-sensor-gpio") peer:

where

The FTY-SENSOR-GPIO-AGENT peer MUST respond with one of the messages back to USER peer using MAILBOX SEND.

where

Store GPO in the agent cache

The USER peer sends the following messages using MAILBOX SEND to FTY-SENSOR-GPIO-AGENT ("fty-sensor-gpio") peer:

where

The FTY-SENSOR-GPIO-AGENT peer MUST NOT respond.