Configuring config.json - PHuhn/py-logger GitHub Wiki

Table of Contents

config.json

The configuration file defines the general functions of the py-logger application. The file is in a JSON (JavaScript Object Notation) file format.

config.json Example

{
  "SensorConfigFile": "config.dat",
  "OutputLogger": "Console",
  "Nrdp": "true",
  "Console": {},
  "File": {
    "Folder": ""
  },
  "Sql": {
    "OdbcDriver": "SQL Server",
    "ServerName": "192.168.0.21\\SQLExpress",
    "Port": "55109",
    "DbName": "Logging",
    "User": "RaspPI",
    "Password": "Colony-0RaspPI-0"
  },
  "Nagios": {
    "Url": "http://localhost/nrdp/",
    "Token": "u%test-token",
    "Host": "raspberrypi",
    "Service": "sensor-logger",
    "State": "0",
    "CheckType": "1"
  }
}

config.json File Format

The JSON file format has four output sections as follows:

  • Console,
  • File,
  • Sql,
  • Nagios.

config.json Console Section

This is the debug option for logging. This allows one to visually test the configuration.

  "Console": {},

The Console section has no additional properties.

config.json File Section

This is the file option for logging. This allows one to have a daily flat file log of activities.

  "File": {
    "Folder": ""
  },

The File section has one properties of "Folder". The "Folder" property contains the file system location for the flat file logs. If the right hand side is empty then the logs will be in the current directory. If in production, it is advised to place the logs in /var/log/py-logger folder.

This is good for a single raspberry pi, but if multiple raspberry pi's are implemented, it is suggest to use the SQL option.

config.json SQL Section

This is the SQL option for logging. If multiple raspberry pi's are implemented per facility, it is suggest to use the SQL option. This option uses the pyodbc library to communicate to the database.

  "Sql": {
    "OdbcDriver": "SQL Server",
    "ServerName": "192.168.0.21\\SQLExpress",
    "Port": "55109",
    "DbName": "Logging",
    "User": "RaspPI",
    "Password": "Colony-0RaspPI-0"
  },
Property Name Description
OdbcDriver Driver system name found in /etc/odbcinst.ini file
ServerName The location on the network to find the database
Port The port # to communicate to the database
DbName The database name on the server
User The user name to connect to the database
Password The password for the above user to connect to the database

config.json Nagios Section

This is the Nagios option for logging. This is an optional logging source, but it adds the a visual component and the ability to notify the responsible person. Please see the NRDP parameter documentation for send_nrdp.py.

  "Nagios": {
    "Url": "http://localhost/nrdp/",
    "Token": "u%test-token",
    "Host": "raspberrypi",
    "Service": "sensor-logger",
    "State": "0",
    "CheckType": "1"
  }
Property Name Description
Url The URL of the NRDP service to log the Nagios log
Token The token for logging found in /usr/local/nrdp/server/config.inc.php file
Host The host name that is displayed on the Nagios web site
Service This is appended to the sensor Id followed by "-", this needs to match configuration in Nagios
State Not used
CheckType The checktype is either 1 for passive or 0 for active

Testing Nagios with send_warn.sh

In the etc folder, is located two bash scripts for testing the Nagios configuration independent of py-logger. After running the scripts, verify the status of execution by checking the visual Nagios Event Logs, and if the service is configured for notification check the visual Notifications page. To view Nagios check the following:

http://<nagios ip address>/nagios/

The two scripts are as follows:

  • send_warn.sh,
  • send_reset.sh.
Example:
pi@raspberrypi:~/r-pi/py-logger/etc $ ./send_warn.sh -h

  Usage: send_warn.sh [options]
  -h    this help text.
  -r    raspberry pi host,   default value: raspberrypi
  -s    Service name,        default value: refrig-116-sensor-logger

  Example:  send_warn.sh -r r-pi01 -s refrig-service-01

pi@raspberrypi:~/r-pi/py-logger/etc $ ./send_warn.sh  -s refrig-116-sensor-logger
Host: raspberrypi, service: refrig-116-sensor-logger
0
pi@raspberrypi:~/r-pi/py-logger/etc $ ./send_reset.sh  -s refrig-116-sensor-logger
Host: raspberrypi, service: refrig-116-sensor-logger
0
pi@raspberrypi:~/r-pi/py-logger/etc $

Good luck...

⚠️ **GitHub.com Fallback** ⚠️