/device-snmp-go

Owner: Device WG

Primary LanguageGoApache License 2.0Apache-2.0

edgexfoundry/device-snmp-go

Build Status Code Coverage Go Report Card GitHub Latest Dev Tag) GitHub Latest Stable Tag) GitHub License GitHub go.mod Go version GitHub Pull Requests GitHub Contributors GitHub Committers GitHub Commit Activity

Warning
The main branch of this repository contains work-in-progress development code for the upcoming release, and is not guaranteed to be stable or working. It is only compatible with the main branch of edgex-compose which uses the Docker images built from the main branch of this repo and other repos.

The source for the latest release can be found at Releases.

Overview:

A generic SNMP device service. Included is a sample for a network switch device driver. Additionally, a Patlite profile is included in the profiles director.

This device service facilitates via the configuration, accessing the TrendNet TEG-082WS 10 port switch. You can send and receive event readings from the network switch. Currently this device service is tailored specifically to the TrendNET TEG-082WS switch but refactoring could take place to abstract the device type and provde a myrida of device profiles. You would need to interrogate the network switch and then determine the appropriate device profile. This particular device service uses the SNMP (Simple Network Management Protocol). SNMP communication with the switch permits the device service to create events based on the Network Switch data. For further information on the Simple Network Management Protocol SNMP Wiki

Build with NATS Messaging

Currently, the NATS Messaging capability (NATS MessageBus) is opt-in at build time. This means that the published Docker images do not include the NATS messaging capability.

The following make commands will build the local binary or local Docker image with NATS messaging capability included.

make build-nats
make docker-nats

The locally built Docker image can then be used in place of the published Docker image in your compose file. See Compose Builder nat-bus option to generate compose file for NATS and local dev images.

TODOS

Async callbacks not supported SNMP Traps are currently not implemented but will be completed at a future date. Network Switch Type abstraction

Packaging

This component is packaged as docker images. Please refer to the Dockerfile and Docker Compose Builder scripts.

Pre-Requisites

device-snmp-go requires Go language. Download the current release if you don't have it already. Have access to the EdgeX Foundry project github site.

EdgeX-Go (The EdgeX Platform and Services)

This service requires the EdgeX-Go platform and several of its services to be up and running if you want to test the device service full integration. However, you can run this service as a standalone with the following minium services up and running either a) natively (.exe) or b) as Docker image containers.

Detailed instructions on how to use the various Edgex-Foundry service(s) are linked below.

Service README
core-data core/core-data/README.md
core-command core/core-command/README.md
core-metadata core/core-metadata/README.md

EdgeX Foundry Images and Containers

If you choose to run the required services or all services as Docker containers you will need to use the Delhi version 0.7.1 of the Edgex-Go Services.

Download from GitHub the EdgeXFoundry developer-scripts project. I download all of my EdgeX Foundry repositories into a parent 'edgexfoundry' directory. The following docker commands assume you have that parent directory in place.

To download the required Delhi versions of the Edgex-Go services perform the following from the console.

cd .../edgexfoundry/developer-scripts/compose-files/
docker-compose up -d 

Now to stop all of the services you and do the following:

cd .../edgexfoundry/developer-scripts/compose-files/
docker-compose down  

Now to stop all of the services and remove the docker volumes do the following:

cd .../edgexfoundry/developer-scripts/compose-files/
docker-compose down -v 

You would want to remove the docker image volumes for anything you persisted. The volumes contain all the data you have published to your edgex-go-mongo as an example. As a general practice I routinely remove my docker volumes. For more information on docker commands see ref Docker Commands

Note: docker-compose.yml is going to be the latest release version of the edgex-foundry project.
For future versions please use the docker-compose-delhi-0.7.1.yml file

GET calls (REST)

For device service get calls we will use our configured static IP address for our network card. You can find this by executing the following: osx. Note you will need to ensure you select your working machine's ethernet static and not any other devices you have on your local network. I have included the SNMP MIB table OID entry(s) so you can see what OID's the device service is using.

arp -a
cheese.attlocal.net (192.168.1.69) [ethernet] ...
...

This is the IP address you will substitute for localhost in the following commands. Verify the deployment by navigating to your server address in your preferred browser or Postman REST test harness. Or you can use the curl command from your console if your on linux or OSX. If you choose to use Postman just use the address less the curl command.

$ curl http://localhost:59993/api/v2/ping

Reboot

The current state of the Network Switch reboot

(SNMP OID) { oid: "1.3.6.1.4.1.28866.2.37.24.5.1.0", community: "private" }
$ curl http://localhost:59993/api/v2/trendnet01/Reboot

UpTime

The switch uptime since last reboot in TimeTicks

(SNMP OID) { oid: "1.3.6.1.4.1.28866.2.37.16.1.1.0", community: "private" }
$ curl http://localhost:59993/api/v2/trendnet01/Uptime

Firmware

The switch firmware version

(SNMP OID) { oid: "1.3.6.1.4.1.28866.2.37.16.1.2.0", community: "private" }
$ curl http://localhost:59993/api/v2/trendnet01/Firmware

MACAddress

The switch MAC Address

(SNMP OID) { oid: "1.3.6.1.4.1.28866.2.37.16.2.1.0", community: "private" }
$ curl http://localhost:59993/api/v2/trendnet01/MacAddress

IPV4Address

The switch IPV4 Address

(SNMP OID) { oid: "1.3.6.1.4.1.28866.2.37.16.1.2.0", community: "private" }
$ curl http://localhost:59993/api/v2/trendnet01/IPV4Address

IPV4SubnetMask

The switch Subnet Mask

(SNMP OID) { oid: "1.3.6.1.4.1.28866.2.37.16.3.3.0", community: "private" }
$ curl http://localhost:59993/api/v2/trendnet01/IPV4SubnetMask

IPV4GatewayAddress

The switch IPV4 Gateway Address

(SNMP OID) { oid: "1.3.6.1.4.1.28866.2.37.16.3.4.0", community: "private" }
$ curl http://localhost:59993/api/v2/trendnet01/IPV4GatewayAddress

PUT calls (REST)

For the set commands we presently just have one. I have included the SNMP MIB OID table entry(s) so you can see what OID's the device service is using.

Reboot

Restarts the switch

(SNMP OID) { oid: "1.3.6.1.4.1.28866.2.37.24.5.1.0", community: "private" }
Parameter Value Description
RebootControlState 1 Restarts the switch
RebootControlState 2 Factory reset and restarts switch
RebootControlState 3 Factory reset, restarts switch with no IP Address
$ curl -H 'Content-Type: application/json' -X PUT -d '{"RebootControlState":"1"}' http://localhost:59993/api/v2/Reboot

Configuration

This service is driven by a configuration.yaml YAML-based file that resides in the directory the application is executed from. See cmd/res/configuration.yaml for default configuration.

References

Website: Dillinger.io "A great README.md file editor"