Zabbix Documentation 3.4

3.04.04.4 (current)| In development:5.0 (devel)| Unsupported:1.82.02.22.43.23.44.2Guidelines

User Tools

Site Tools


Sidebar

manual:appendix:command_execution

This is an old revision of the document!


9 Command execution

Zabbix uses common functionality to execute user parameters, remote commands, system.run[] items without the “nowait” flag, scripts (alert, external and global) and some internal commands.

Execution steps

The command/script is executed similarly on both Unix and Windows platforms:

  1. Zabbix (the parent process) creates a pipe for communication
  2. Zabbix sets the pipe as the output for the to-be-created child process
  3. Zabbix creates the child process (runs the command/script)
  4. A new process group (in Unix) or a job (in Windows) is created for the child process
  5. 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.
  6. If the timeout has not been reached, Zabbix waits until the initial child process exits or timeout occurs
  7. 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)
  8. 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
Steps 5-8 do not refer to remote commands as they are executed with a “nowait” flag. Step 7 does not refer to custom scripts executed by Zabbix agent.
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.

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 checks for the executed commands/scripts are performed with the following conditions:

  • Exit codes for scripts, remote commands, user parameters and for Zabbix agent items system.run (without the “nowait” flag), system.hw.devices, and system.sw.packages are checked.
  • 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.

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 user parameters, remote commands, alert scripts.