Zabbix Documentation 5.0

3.04.05.0 (current)| In development:5.2 (devel)| Unsupported:1.82.02.22.43.23.44.24.4Guidelines

User Tools

Site Tools


manual:appendix:command_execution

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
manual:appendix:command_execution [2017/10/10 14:32]
martins-v updated command execution to better reflect what is happenning
manual:appendix:command_execution [2018/10/01 09:42]
Line 1: Line 1:
-==== 10 Command execution ==== 
- 
-Zabbix uses common functionality for external checks, user parameters, system.run items, custom alert scripts, remote commands and user scripts. 
- 
-=== Execution steps === 
- 
-The command/​script is executed similarly on both Unix and Windows platforms: 
-  - Zabbix (the parent process) creates a pipe for communication 
-  - Zabbix sets the pipe as the output for the to-be-created child process 
-  - Zabbix creates the child process (runs the command/​script) 
-  - A new process group (in Unix) or a job (in Windows) is created for the child process 
-  - Zabbix reads from the pipe until timeout occurs or no one is writing to the other end (ALL handles/​file descriptors have been closed). Note that the child process can create more processes and exit before they exit or close the handle/file descriptor. 
-  - If the timeout has not been reached, Zabbix waits until the initial child process exits or timeout occurs 
-  - If the initial child process exited and the timeout has not been reached, Zabbix checks exit code of the initial child process and compares it to 0 (non-zero value is considered as execution failure, only for custom alert scripts, remote commands and user scripts executed on Zabbix server and Zabbix proxy) 
-  - At this point it is assumed that everything is done and the whole process tree (i.e. the process group or the job) is terminated 
- 
-<note important>​Zabbix assumes that a command/​script has done processing when the initial child process has exited AND no other process is still keeping the output handle/file descriptor open. When processing is done, ALL created processes are terminated.</​note>​ 
- 
-All double quotes and backslashes in the command are escaped with backslashes and the command is enclosed in double quotes. 
- 
-=== Exit code checking === 
- 
-Exit code are checked with the following conditions: 
- 
-  *Only for custom alert scripts, remote commands and user scripts executed on Zabbix server and Zabbix proxy. 
-  *Any exit code that is different from 0 is considered as execution failure. 
-  *Contents of standard error and standard output for failed executions are collected and available in frontend (where execution result is displayed). 
-  *Additional log entry is created for remote commands on Zabbix server to save script execution output and can be enabled using LogRemoteCommands agent [[:​manual/​appendix/​config/​zabbix_agentd|parameter]]. 
- 
-Possible frontend messages and log entries for failed commands/​scripts:​ 
-  * Contents of standard error and standard output for failed executions (if any). 
-  * %%"​%%Process exited with code: N.%%"​%% (for empty output, and exit code not equal to 0). 
-  * %%"​%%Process killed by signal: N.%%"​%% (for process terminated by a signal, on Linux only). 
-  * %%"​%%Process terminated unexpectedly.%%"​%% (for process terminated for unknown reasons). 
- 
----- 
- 
-Read more about [[manual:​config:​items:​userparameters|user parameters]],​ [[manual:​config:​notifications:​action:​operation:​remote_command|remote commands]], [[manual:​config:​notifications:​media:​script|alert scripts]]. 
-