(DI-2211) Collector to execute system shell commands
The technical name of the Collector to execute system shell commands is /DVD/MON_CL_COL_SYS_CMD.
This collector can execute predefined or custom shell commands, and extract any basic information from the command execution’s output. Please note that this collector will not report a complete command output, but only a numerical value based on the defined KPI and its regular expression defined in the Input table. There are two possible ways how to define system commands in the Input table:
Use an existing SXPG command name (already defined in transactions SM49 or SM69).
If defined SXPG commands should be executed on the remote SAP system(s), they must also be created and defined on the monitored remote SAP system.
SXPG command provides you a safer way of custom system commands execution (e.g. custom check module can be set for any additional checks before its execution).
Use a custom command (custom command string is directly defined in the collector’s Input table).
If this command should be executed on remote SAP system(s), it does not have to be defined on the monitored remote SAP system (it’s directly executed on the remote SAP system).
There is no possibility to define any other additional checks except the predefined collector’s checks (e.g. authorization checks for System commands execution).
In both scenarios, the user who is executing this collector needs to have assigned authorizations for executing System commands.
Collector works for Linux and Windows based systems, but system commands from Linux will not work on Windows based system. It is recommended to use predefined SXPG commands instead of custom commands, as SXPG commands can be tested directly on specific system in transaction SM49 or SM69.
Default KPIs delivered with this collector
The following default KPI is delivered with this collector. This KPI is not in the default monitoring scope and serves as a template KPI for a new custom KPI creation.
KPI name | Description | Unit |
---|---|---|
OS_RUN_PS_COUNT | Get number of running processes on OS | Count |
If you want to calculate any custom KPI based on any system command, you need to define a custom KPI (starting with Z* or Y*) first. You might use the template KPI ‘OS_RUN_PS_COUNT’ to Define a Custom KPI.
When any custom KPI created, it has to be assigned to this collector as described in general procedure How to Create a Custom KPI through a Collector with a Custom KPI.
Input table
The system commands collector uses the Input table /DVD/MON_SYSCMD1.
The rules in the Input table define the list of system commands based on which are calculated specified KPIs. The Input table provides the following fields:
Technical name | Column name | Description |
KPI | KPI | Name of the KPI that rule applies to (custom Z* or Y* KPI created in previous step). |
COMMAND_NAME | Command name | SXPG Command name - this field has to be filled if the user wants to use an existing SXPG command defined in SM49/SM69. If user doesn’t want to use any SXPG command (but rather use any custom command), leave this field empty. |
COMMAND_TEXT | Command text | This field allows you to define a custom system command definition (if you have already using SXPG command, leave this field empty). If you would like to use a custom system command, type the text of the command into this field (for example, Linux command “- ps” or Windows command “- ipconfig”). Custom commands support also piping “|” and quotation marks. However, it is still recommended to use predefined commands for longer and more complex command executions. |
ADD_PARAMS | Additional parameters | You might enter enter any additional parameters for the command execution into this field. This field can be used for both command types (SXPG command or custom command). |
REGEXP | Regular expression | Field for regular expression allows you to define a regular expression to be applied and matched in the executed command output. Command output is parsed and every occurrence of defined regex will be counted into the KPI calculation . |
REQ_VALUE | Requested value | Defines the value for KPI calculation (KPI can be only a numerical value). It is possible to define the following requested values:
|
CHANGED_BY | Change by user | Last change by user [automatically filled] |
CHANGED_AT | Change date | Last change date [automatically filled] |
CREATED_BY | Created by | Created by user [automatically filled] |
CREATED_AT | Created at | Created at [automatically filled] |
Working examples
These examples just show you, how to format your system commands based on the script, you would like to use. You might define either a whole command in the Command text field or split it into the Command text and Additional parameters fields. Please keep in mind that you won’t be able to extract the raw output of this command and report it as KPI, but you have to also set a valid value in the Requested value field with a valid regular expression.
Examples of Linux-based system
Basic shell command
ps -aux | grep "java" - command counts how many processes run under java
Bash
bash -c "echo $SAPSYSTEMNAME" - command prints the SAP system name
Perl
echo `perl -MPOSIX -le 'print strftime "%Y-%m-%d-%H.%M.%S",gmtime(1636897305)'`- command formats the Unix timestamp to real timestamp
Examples of Windows-based system
Basic CMD command
driverquery /FO list /v - commands return a list of installed drivers
PowerShell
powershell "Get-Service | Where-Object {$_.Status -match 'Running'}" - command prints all running services on the OS level
Perl
perl -e "print 55" - command prints the number 55