When a Zabbix trigger reaches a threshold, an action is executed: sending an alert message or executing a remote command. This article mainly configures and verifies that zabbix executes remote commands. one. environmentServer: Based on CentOS-7-x86_64-1511; Zabbix: zabbix-3.0.1server/agent. two. PrecautionsSome important things to note: 1. Remote command execution is from the server to the agent, and does not support active agent mode; 2. Proxy mode is not supported; 3. The zabbix user must have execution permissions for the command, and can use sudo to grant root permissions (configure sudo without password); 4. The remote command is only executed, and the success or failure of the execution is not detected and confirmed. You can check the action execution in "Monitoring-->Events", or check whether the remote command is executed successfully in "Reports-->Action log" (successful execution is "Executed"). three. ExampleVerify with a simple example: The number of real-time online users on the monitoring server does not exceed 2. When the threshold is exceeded, an alarm is triggered and a command is executed to force the third logged-in user to log off so that the monitoring item is below the threshold. 1. Set the Trigger Configuration-->Templates-->Select "Template OS Linux" template "Triggers"-->Create trigger #trigger name customization, you can use macros Name:User login number gt 2 on {HOST.NAME} Expression: {Template OS Linux:system.users.num.last()}>2 #You can click "Add" after the "Expression" item and use the Item + Function provided by Zabbix to set the threshold expression as follows: #Custom level Severity: Warning The rest of the settings are acceptable. After completing the settings, click "Add". 2. Remote command switch #Agent does not support executing remote commands by default. You need to enable this parameter in the agent configuration file; #The agent.conf file path should be modified according to the actual situation. Here is the customized path after compilation and installation. Please see http://www.cnblogs.com/netonline/p/7406598.html #After the agent.conf file is modified, the process needs to be restarted. [root@localhost ~]# sed -i 's|# EnableRemoteCommands=0|EnableRemoteCommands=1|g' /usr/local/zabbix/etc/zabbix_agentd.conf [root@localhost ~]# service zabbix_agentd restart 3. Set Action Configuration-->Actions-->Create action Action In the Action option, define Name: Limit the number of online users no more than 2 #You can customize the action name, and the rest of the action options can use the default values, as follows: Conditions Add new conditional judgments in the Conditions option to make the judgment more targeted, such as: New condition: Trigger severity = Warning New condition: Trigger name like User login number gt 2 #trigger name corresponds to the trigger name defined in step 1, as follows: Operations In the Operations option, add a new "Action operation" and click "New". Operation type: Select "Remote Command" Target list: Add target as "Current host" #agent on this machine Type: Select "Custom script" Execute on: Select "Zabbix agent" and the command is " #The account that executes the command is the zabbix account, not the root account. Not using the sudo command will cause the command to be ineffective after execution. #In addition, I have tried to use specific commands instead of scripts. The result is that the command is executed but not effective. Because there is no specific failure log, the reason cannot be analyzed. #Use the default values for the rest of the content and click "Add", as shown below: 4. Remote command script #Edit the command script according to the path of the command script defined in step 3; [root@localhost ~]# vim test.sh #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH #Here we simply assume that the third login tty is pts/2 pkill -kill -t pts/2 [root@localhost ~]# chmod 764 test.sh 5. Configure sudo
6. Verification Remotely log in to the third tty of the host, do not perform any other operations in the CLI, trigger the trigger threshold, and trigger the command action to force the third logged-in user to go offline. As can be seen from the screenshot, when the number of online users exceeds the threshold, the trigger is in the "PROBLEM" state for only about 1 minute and then returns to the "OK" state, indicating that the script command forcing the third user to go offline has been executed and executed successfully. From the historical data of the "Number of logged in users" Item, we can also see that when the trigger is triggered, the third logged-in user is offline. Under the third tty, you can see that the connection is disconnected by the host itself (the local time is displayed, which deviates from the host time in the above figure). Summarize This is the end of this article about Zabbix remote execution commands. For more related Zabbix remote execution commands, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Examples of using MySQL pessimistic locking and optimistic locking
>>: Vue+swiper realizes timeline effect
As an entry-level Linux user, I have used simple ...
Table of contents 1. Introduction 2. Configuratio...
I upgraded my Raspberry Pi server to Ubuntu 20 tw...
location matching order 1. "=" prefix i...
Table of contents Standard execution process opti...
Install the unzipped version of MySql database un...
This article shares the specific code of vue elem...
0. Background Hardware: Xiaomi Notebook Air 13/In...
Table of contents 1. Create objects by literal va...
Content Detail Tags: <h1>~<h6>Title T...
1. CSS file naming conventions Suggestion: Use le...
Conventional solution Use FileReader to read the ...
<br />The header refers to the first row of ...
Related knowledge points Passing values from pa...
There are many commands used in the system, so ho...