PyMonitorMQTT | Python computer monitor that sends real time information via MQTT

PyMonitorMQTT

Terminal Command

This commands is used to run the command (specified in the message or in the configuration file). To configure, read the paragraph below.

Compatibility

Data and Topics

.../terminal_command payload not needed

Run terminal command

Payload JSON
command optional
String Command to run, must be allowed using special configurations that you can find in the paragraph below.

Configuration

custom_topics optional
List of String List of topics to which the command will subscribe.
If the command subscribes to a single topic, you will have to put one topic in the list.
If the command subscribes to more than one topic, you can register more topics; each topic in the list will be assigned in the same order as topics are added from the single commands (order that you can check in the each individual command file).
contents required
Dictionary Dictionary where you should put the data you want to pass to the command.
command optional
String Here you can place the command you want to run every time tht you send a message to the Command topic: if you specify here the command, you don't have to add whitelist options
whitelist optional
Dictionary/List Here you can specify the rules for the command the received messge wants to execute: normally a network command is not secure to run so here you can setup here your security policy

There are two ways to select the command to run

Set command in the configuration file

If you set the command in the configuration file, you don’t have to specify any whitelist because the command can’t be edited from the network. The message you send to the topic to trigger the command won’t be read and if you specify a command there won’t be considered.

To run multiple commands, each one specified in the configuration file, you have to consider using a custom_topic.

Example

Here you have 2 commands:

extract of configuration.yaml

    commands:
      - Terminal:
          custom_topics:
            - mycommand/topic/number1
          contents:
            command: "echo Ready > file.txt"
      - Terminal:
          custom_topics:
            - mycommand/topic2
          contents:
            command: "mkdir Try"

If you don’t set a command in the configuration file, the Monitor will look for the command in the message payload:

Run command specified via message

Maybe you prefer sending the command with the message. For security reason, you have to specify in the configuration file which command can be run.

To use this feature:

Examples

Whitelist

Allow commands that start with “google-chrome” and with “vlc”

extract of configuration.yaml

    commands:
      - Terminal:
          custom_topics:
            - mywhitelistedcommands
          contents:
            whitelist: 
              - google-chrome*
              - vlc*

First message

This message asks to run google-chrome www.youtube.com and this command will be run

message payload

{
    "command": "google-chrome www.youtube.com"
}

Second message

This message asks to run shutdown now and this command won’t be run

message payload

{
    "command": "shutdown now"
}

Allow

Allow every command you receive

extract of configuration.yaml

    commands:
      - Terminal:
          custom_topics:
            - myallowedcommands
          contents:
            whitelist: allow

Deny

Deny every command you receive

extract of configuration.yaml

    commands:
      - Terminal:
          custom_topics:
            - mydeniedcommands
          contents:
            whitelist: deny