Shell Interface

With this 'interface' you can run a binary or shell script and either:
  • parse the results, these result values will be put in the value fields of the device.
  • or have DomotiGa call the script with 'On' or 'Off' to have the script set the device

For importing values, the tool or the script should return one or more values separated by newlines:

$ /usr/local/bin/upnp2mrtg
4245720540
1990146295

See the examples below:

Configuration

First things to do is to enable the Shell module under Interfaces -> Shell:

Next step is to one or more add devices:
  • Device Id assigned by Domotiga
  • The Name string will be used in the Device overview and must be unique
  • The Type must be set to Shell
  • Device and Interface will be automatically set
  • Put in the Command field the command, optionally with arguments, to execute
  • Icon On/Dim/Off gives the icon Domotiga will show in the Device overview window
     

For switching (or dimming) devices, go to the Options tab of the device and enable either "Device can be switched" or "Device can be dimmed"

Examples

Fritz!Box

For example to measure internet traffic flowing through a Fritz!Box you can set it up as follow:

Create device "Internet Traffic"
Devicetype "Shell"
As address put in the script/command to run, in this case: /usr/local/bin/upnp2mrtg

Warning: If you use a newer FritzOS version on your router (and you should!) the link below downloads an incompatible script, if you use this it will fail to download the data from the Fritz!Box and you end up with a device and 46 values attached ;-)

Use the upnp2mrtg script attached to this wiki page instead.

You can install and test it from the shell like so:

$ cd ~install
$ wget http://www.anetzb.de/upnp2mrtg/upnp2mrtg
$ chmod +x upnp2mrtg
$ sudo cp upnp2mrtg /usr/local/bin
$ /usr/local/bin/upnp2mrtg
4245720540
1990146295
7 days 22:38:11 h (online)
Fritz!Box

There should be no need to change the script, it should find your Fritz!Box automatically.

Update (June 2014): A recent version of the Fritzbox Firmware breaks the upnp2mrtg script and may cause the
script to report http 500 internal server error instead of the traffic values. Fortunately the resolution is
quite simple. Edit the /use/local/bin/upnp2mrtg file, and in the request_header function, change
echo "POST /upnp/control/$4 HTTP/1.0
to
echo "POST /igdupnp/control/$4 HTTP/1.0
i.e. insert igd after the first / and before upnp

If you want to graph you Internet Traffic values
Tick Log RRD data on device tab Graphs.
Name DataSource Name Value1 "download" and select type COUNTER
Name DataSource Name Value2 "upload" and select type COUNTER

You can now define a Extended graph, to display your Incoming and Outgoing traffic.

Go to Edit Graphs
Create new one for example "Internet Traffic"
Fill in new Name and Title, click on Save, reopen it.
Unit

Click tab Graph Data
Select ID 1
Name Download
DS Internet Traffic download
Type LINE1 Color <your color>

Click Save

Select ID 2
Name Upload
DS Internet Traffic upload
Type LINE2 Color <your color>

Click Save

Click tab Groups
Put it in group Network

Click Save

You can click on Preview to see if it looks ok.

Resources:
http://www.anetzb.de/upnp2mrtg/
http://www.anetzb.de/upnp2mrtg/upnp2mrtg

SNMP monitoring

You can also create a custom script to get other values, for example SNMP,

Monitor a Synology NAS with SNMP

First enable SNMP first on a Synology (under Network Settings/SNMP)

#!/bin/sh
# example script to get snmp values in DomotiGa device fields

value1 = `snmpwalk ...`
value2 = `snmpwalk ...`
value2 = `snmpwalk ...`

echo value1
echo value2
echo value3

After this test simply do this:

Enable Shell Interface
Check polltime to run.
NOTE: this time is the same for all devices of type Shell Value.

On the next run, the values of the device should be filled.
It take each line and put it in a value, so line1 = value1, line2 = value2 etc.

snmpwalk output regarding memory:

iso.3.6.1.2.1.25.2.3.1.3.1 = STRING: "Physical memory" 
iso.3.6.1.2.1.25.2.3.1.3.3 = STRING: "Virtual memory" 
iso.3.6.1.2.1.25.2.3.1.3.6 = STRING: "Memory buffers" 
iso.3.6.1.2.1.25.2.3.1.3.7 = STRING: "Cached memory" 
iso.3.6.1.2.1.25.2.3.1.3.10 = STRING: "Swap space" 
iso.3.6.1.2.1.25.2.3.1.3.31 = STRING: "/" 
iso.3.6.1.2.1.25.2.3.1.3.32 = STRING: "/volume1" 
iso.3.6.1.2.1.25.2.3.1.3.33 = STRING: "/volume1/myhome" 
iso.3.6.1.2.1.25.2.3.1.4.1 = INTEGER: 1024
iso.3.6.1.2.1.25.2.3.1.4.3 = INTEGER: 1024
iso.3.6.1.2.1.25.2.3.1.4.6 = INTEGER: 1024
iso.3.6.1.2.1.25.2.3.1.4.7 = INTEGER: 1024
iso.3.6.1.2.1.25.2.3.1.4.10 = INTEGER: 1024
iso.3.6.1.2.1.25.2.3.1.4.31 = INTEGER: 4096
iso.3.6.1.2.1.25.2.3.1.4.32 = INTEGER: 4096
iso.3.6.1.2.1.25.2.3.1.4.33 = INTEGER: 4096
iso.3.6.1.2.1.25.2.3.1.5.1 = INTEGER: 515556
iso.3.6.1.2.1.25.2.3.1.5.3 = INTEGER: 2612636
iso.3.6.1.2.1.25.2.3.1.5.6 = INTEGER: 515556
iso.3.6.1.2.1.25.2.3.1.5.7 = INTEGER: 249828
iso.3.6.1.2.1.25.2.3.1.5.10 = INTEGER: 2097080
iso.3.6.1.2.1.25.2.3.1.5.31 = INTEGER: 612766
iso.3.6.1.2.1.25.2.3.1.5.32 = INTEGER: 1078116418
iso.3.6.1.2.1.25.2.3.1.5.33 = INTEGER: 1078116418
iso.3.6.1.2.1.25.2.3.1.6.1 = INTEGER: 502304
iso.3.6.1.2.1.25.2.3.1.6.3 = INTEGER: 502304
iso.3.6.1.2.1.25.2.3.1.6.6 = INTEGER: 68084
iso.3.6.1.2.1.25.2.3.1.6.7 = INTEGER: 249828
iso.3.6.1.2.1.25.2.3.1.6.10 = INTEGER: 0
iso.3.6.1.2.1.25.2.3.1.6.31 = INTEGER: 134322
iso.3.6.1.2.1.25.2.3.1.6.32 = INTEGER: 1076977576
iso.3.6.1.2.1.25.2.3.1.6.33 = INTEGER: 1076977576
iso.3.6.1.2.1.25.3.2.1.1.768 = INTEGER: 768
iso.3.6.1.2.1.25.3.2.1.1.1025 = INTEGER: 1025
iso.3.6.1.2.1.25.3.2.1.1.1026 = INTEGER: 1026
iso.3.6.1.2.1.25.3.2.1.1.1536 = INTEGER: 1536
iso.3.6.1.2.1.25.3.2.1.1.1537 = INTEGER: 1537
iso.3.6.1.2.1.25.3.2.1.1.1538 = INTEGER: 1538
iso.3.6.1.2.1.25.3.2.1.1.1539 = INTEGER: 1539
iso.3.6.1.2.1.25.3.2.1.1.1552 = INTEGER: 1552
iso.3.6.1.2.1.25.3.2.1.1.1553 = INTEGER: 1553
iso.3.6.1.2.1.25.3.2.1.1.1554 = INTEGER: 1554
iso.3.6.1.2.1.25.3.2.1.1.1555 = INTEGER: 1555
iso.3.6.1.2.1.25.3.2.1.1.1568 = INTEGER: 1568
iso.3.6.1.2.1.25.3.2.1.1.1569 = INTEGER: 1569
iso.3.6.1.2.1.25.3.2.1.1.3072 = INTEGER: 3072

Switch device

If you have devices not supported by DomotiGa natively, but you have a script to control them with you can do the following.

Create a script, for example "relais1.sh"

$ vi /home/ron/domotiga/scripts/relais1.sh
#!/bin/bash

stty -F /dev/ttyACM0 9600 2>/dev/null
if [ $1 == 'On' ]
then
  echo -e '\xff\x01\x01' > /dev/ttyACM0 2>/dev/null
  echo 'On'
else
  echo -e '\xff\x01\x00' > /dev/ttyACM0 2>/dev/null
  echo 'Off'
fi

Make the script executable:

$ chmod +x relais1.sh

Create a Shell device in DomotiGa, set the address to the absolute path of this script.
Make it switchable in the device options.

Now you can control it by clicking the button on the Control page, and the scripts get's called with argument "On" or "Off".

The shell script needs to/can report back the status as well, here done with the echo 'On/Off's.

This example switches relais 1 of a KMtronic 8 channel relais card.

Resources

    Updated by: rdnzl, Updated over 2 years ago
    Access count: 67176 since 2011-11-13

    Attached Files

    shell-device.png (56.9 KB) rdnzl, 05/08/2012 07:50 PM

    internet-traffic.png (20.5 KB) rdnzl, 05/08/2012 07:50 PM

    KMtronic_Relais.jpg (32.2 KB) rdnzl, 11/27/2012 01:15 PM

    Shell_settings.png (18.2 KB) danfos, 09/21/2014 04:09 PM

    Shell_device.png (42.9 KB) danfos, 09/21/2014 04:11 PM

    upnp2mrtg - Compatible with newer FritzOS versions (5.52 KB) rdnzl, 11/21/2014 10:18 AM

    Also available in: PDF HTML TXT