Manual:Tools/Sigwatch

From MikroTik Wiki
(Redirected from Sigwatch)
Jump to navigation Jump to search

Applies to RouterOS: All

The Sigwatch utility monitors state of attached asynchronous serial ports and generates system events upon state change.

Requirements

Sigwatch is available only on X86 (PC) platform. Advanced Tools package is required.

Settings

  • count (read-only: integer) - how many times the event for this item was triggered. Count is reset on reboot and on most item configuration changes
  • log (yes | no; default: no) - whether to add a message in form of name-of-sigwatch-item: signal changed [to high | to low] to System-Info facility whenever this sigwatch item is triggered
  • name (name) - name of the sigwatch item
  • on-condition (on | off | change; default: on) - on what condition to trigger action of this item
    • on - trigger when state of pin changes to high
    • off - trigger when state of pin changes to low
    • change - trigger whenever state of pin changes. If state of pin changes rapidly, there might be triggered only one action for several state changes
  • port (name) - serial port name to monitor
  • script (name) - script to execute when this item is trigered
  • signal (dtr | rts | cts | dcd | ri | dsr; default: rts) - name of signal of number of pin (for standard 9-pin connector) to monitor
    • dtr - Data Terminal Ready (pin #4)
    • rts - Request To Send (pin #7)
    • cts - Clear To Send (pin #8)
    • dcd - Data Carrier Detect (pin #1)
    • ri - Ring Indicator (pin #9)
    • dsr - Data Set Ready (pin #6)
  • state (read-only: text) - last remembered state of monitored signalcount (read-only: integer) - how many times the event for this item was triggered. Count is reset on reboot and on most item configuration changes

Note: You can type actual script source instead of the script name from /system script list.

Example

In the following example we will add a new sigwatch item that monitors whether the port serial1 has cts signal.


[admin@MikroTik] tool sigwatch> print
Flags: X - disabled
  #   NAME                                  PORT    SIGNAL     ON-CONDITION LOG
  0   test                                  serial1 cts        change       no
[admin@MikroTik] tool sigwatch>

By typing a command print detail interval=1s, we can check whether a cable is connected or it is not. See the state argument - if the cable is connected to the serial port, it shows on, otherwise it will be off.

[admin@MikroTik] tool sigwatch> print detail
Flags: X - disabled
  0   name="test" port=serial1 signal=cts on-condition=change log=no script=""
      count=1 state=on

[admin@MikroTik] tool sigwatch> print detail
Flags: X - disabled
  0   name="test" port=serial1 signal=cts on-condition=change log=no script=""
      count=1 state=on

[admin@MikroTik] tool sigwatch> print detail
Flags: X - disabled
  0   name="test" port=serial1 signal=cts on-condition=change log=no script=""
      count=2 state=off

[admin@MikroTik] tool sigwatch> print detail
Flags: X - disabled
  0   name="test" port=serial1 signal=cts on-condition=change log=no script=""
      count=2 state=off

[admin@MikroTik] tool sigwatch>

In the port menu you can see what signal is used by serial cable. For example, without any cables it looks like this:

[admin@MikroTik] port> print stats
  0 name="serial0" line-state=dtr,rts

  1 name="serial1" line-state=dtr,rts
[admin@MikroTik] port>

But after adding a serial cable to the serial port:

[admin@MikroTik] port> print stats
  0 name="serial0" line-state=dtr,rts

  1 name="serial1" line-state=dtr,rts,cts
[admin@MikroTik] port>

This means that the line-state besides the dtr and rts signals has also cts when a serial cable is connected. The example below will execute a script whenever on-condition changes to off:

[admin@MikroTik] tool sigwatch> print detail
Flags: X - disabled
  0   name="cts_rest" port=serial1 signal=cts on-condition=off log=no
      script=/system shutdown count=0 state=on
[admin@MikroTik] tool sigwatch>

It means that if a serial cable is connected to the serial port, all works fine, but as soon as it is disconnected, the router shuts down. It will continue all the time until the serial cable will not be connected again.