This article applies to TeamViewer IoT users who monitor their IoT networks.

The solution presented in this article requires TeamViewer IoT Agent v 1.1.102 (or higher).  To identify the version of your agent, run: sudo teamviewer-iot-agent info (an error, or no result, indicates an older version of the agent is installed).

Description

As described in the  Custom Plugin Connector article, it's quite easy to monitor your sensor network via TeamViewer IoT.  This article describes how to use the TeamViewer IoT Log Parser Connector to easily extract & integrate sensor data from your log files.  The Log Parser is generic, in that, it can be used to parse any log.  For the context of this article, it is assumed your IoT sensor values are written to a log file which you would like to connect to the TeamViewer IoT Agent.

Step 1 - Install dependencies

The connector requires the following to be installed on the device:

Step 2 - Download and install the Log Parser Connector

  1. From your device running the TeamViewer IoT Agent, download the connector: 
    wget  https://download.teamviewer-iot.com/connectors/teamviewer-iot-log-parser/1.0.0/teamviewer_iot_log_parser-1.0.0.tar.gz
  2. Upon download completion, extract the contents of the connector:
    sudo mkdir -p /usr/local/teamviewer-iot-agent/monitoring/
    tar -xzvf teamviewer_iot_log_parser-1.0.0.tar.gz -C /usr/local/teamviewer-iot-agent/monitoring/
  3. Install the Connector
    cd teamviewer_iot_log_parser-1.0.0
    python3 setup.py install
  4. Verify the installation was successful by identifying a log file to parse and using the following command to parse a string.  Replace logFilePath & justTextorRegex with the path of your log file and a string to search for, respectively.
    teamviewer_iot_log_parser -f logFilePath --regex justTextOrRegex

 

Step 3 – Get to know the TeamViewer Log Parser Connector

The connector will integrate with the TeamViewer IoT Agent as will be discussed in the next section.  Prior to integrating the connector, the connector configuration and syntax should be reviewed.

The connector can be configured given the following configuration arguments:

TeamViewer IoT Log Parser Connector

Argument / flag

Required?

Description

-p, --parser

True

The log parser can operate in 2 modes:

matches – (Default) returns a count of strings matching a specified regex since the last run

metrics – returns an aggregated value for each specified metric since the last run

-t, --timeout

True

Duration to wait for parsing to complete before terminating and returning an error.

Values are in seconds; Default, if not specified, is 5 seconds.

 

The two modes of operation, (Matches & Metrics), each require additional parameters to be specified:

Matches

Argument / flag

Required?

Description

-f, --file         

True

File path of the log to parse

-R, --regex

True

String or regex expression to match

For regex details, reference: https://docs.python.org/3/library/re.html

 

Metrics

Argument / flag

Required?

Description

-f, --file

True

File path of the log to parse

-M, --metrics

True

Space delimited list of metrics to extract

-A, --aggfunctions

True

Space delimited list of aggregation functions for each respective metric

Possible values: avg, sum, min, max, median

-T, --template

False

Template to parse metrics

Default template is :metric=.(.*?).[\s], which will match log entries of “metricName"="value"

 

Step 4 – Integrate the Log Parser Connector with the TeamViewer IoT Agent 

The TeamViewer IoT Agent includes its own system monitoring configuration file.  This configuration file will be extended to include the Log Parser configuration.  As you are going to maually edit a system configuration file, ensure to create a backup of the file in the case the file gets corrupted by user error.

  1. Open for editing the TeamViewer IoT Agent monitoring configuration file located at:
    • /var/lib/teamviewer-iot-agent/system_monitors.conf
    • sensors are hosted under the "sensors" node of the configuration file
  2. For each sensor you want to integrate, append its registration information to the configuration file.  Reference the template below and replace the placeholders with your sensor details.
  3. Save the configuration file.
  4. Restart the agent to reload the configuration file.
    • teamviewer-iot-agent restart
  5.  Log into your TeamViewer IoT dashboard and verify that the Sensors/Metrics added to the configuration file now appear on your Metrics tab.
    • Pin the metrics to your dashboard and ensure the data is being updated per the frequency specified in the config file

TeamViewer IoT Log Parser Connector Template

Use the following template to add your connector configuration for each sensor to the monitoring configuration file.  The template is an example of adding a single sensor with two (2) metrics (Temperature & Humidity).

Ensure to replace the following placeholders with the specifics of your sensor.  Note:  the frequency in the template is set to 10, which will trigger the Log Parser Connector to run every 10 seconds, aggregating the values from each interval.

More details about the JSON schema can be found in the  Custom Plugin Connector article.

{
    "sensors": [
        {
            "name": "temperature_humidity_parser",
            "monitoringService": "python3 /usr/local/teamviewer-iot-agent/monitoring/log_parser/teamviewer_iot_log_parser.py",
            "monitoringParams": "--file /tmp/file.log  --parser metrics -–metrics temperature humidity --aggfunctions max avg –-template ':metric=.(.*?).[\\s]'",
            "frequency": 10,
            "metrics": [{
                    "name": "Temperature",
                    "key": "temperature",
                    "valueType": "double",
                    "valueAnnotation": "C"
                }, {
                    "name": "Humidity",
                    "key": "humidity",
                    "valueType": "double",
                    "valueAnnotation": ""
                }
            ]
        },
        ...
    ]
}

Note: the metrics.key in the config file should be same as in the monitoringParams parameter. The metrics.name can be any string as it will be the display name of the metric in the TeamViewer IoT Cloud dashhboard.

monitoringParams Examples

The following examples describe use cases and their respective configuration of the connector as specified by the monitoringParams parameter:

  1. Parse a log file to retrieve the maximum value of a metric called “temperature” and the average value of a metric called “humidity”.
>> Log File (log_file.log) Contents:
some text temperature=18 some text humidity=80
some other text temperature=19 some text humidity=82 text

>> monitoringParams:
--file log_file.log --parser metrics --metrics temperature humidity --aggfunctions max avg --template=":metric=(.*?)[\\s]"

>> Result:
{"temperature": 19, "humidity":81}

 

  1. Parse a log file to retrieve the number of occurrences of the string “findMe".
>> Log File (log_file.log) Contents:
some text findMe some text findMe
some other text temperature=19 some findMe text humidity=82 text

>> monitoringParams: 
--file log_file.log --parser matches --regex someRegex

>> Result:
 {"count": 3}

 

 

Version history
Revision #:
4 of 4
Last update:
‎11 10 2018, 10:10 AM
Updated by:
 
Labels (4)
Contributors