In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
After the Zabbix trigger (trigger) reaches the threshold, there is an action (action) to execute: send an alarm message or execute a remote command.
The main purpose of this article is to configure and verify that zabbix executes remote commands.
One. Environment
Server: based on CentOS-7-x86_64-1511
Zabbix:zabbix-3.0.1server/agent .
Two. matters needing attention
Some more important points for attention that can be thought of: 1. Remote execution commands are executed from the server side to the agent side, and active mode agent; 2. 0 is not supported. Proxy mode is not supported; 3.zabbix users must have execute permissions on commands and can use sudo to grant root permissions (configure sudo password-free mode)
4. The remote command is only executed, and the success of the execution is not detected and confirmed. You can see whether the remote command is executed successfully in "Monitoring-- > Events" or in "Reports-- > Action log" (success is "Executed").
III. Exampl
Verify through a simple example:
The monitoring server has no more than 2 users online in real time, give an alarm when the threshold is exceeded, and execute the command to force the third logged-in user to be offline, so that the monitoring item is below the threshold.
1. Set up Trigger
Configuration-- > Templates-- > Select "Triggers" of the "Template OS Linux" template-- > 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 "Expression", and use the Item + Function expression that comes with zabbix to set the threshold, as follows:
# customized level
Severity:Warning
The rest of the default values are fine. Click "Add" after the setting is completed.
two。 Remote command switch
# agent does not support the execution of remote commands by default, so you need to enable this parameter in the configuration file of agent. The path of # agent.conf file is modified according to the actual situation. Here is the path that is customized after compilation and installation. Please see http://www.cnblogs.com/netonline/p/7406598.html#agent.conf file modification and restart the process. [root@localhost ~] # sed-I's | # EnableRemoteCommands=0 | EnableRemoteCommands=1 | g' / usr/local/zabbix/etc/zabbix_ agentd.confs [root @ localhost ~] # service zabbix_agentd restart
3. Set up Action
Configuration-- > Actions-- > Create action
Action
In the Action option, define Name:Limit the number of online users no more than 2
# action name can be customized. Default values can be used for the rest of the action options, as follows:
Conditions
Add a new conditional judgment to 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 to "Current host" # agent on the local machine
Type: select "Custom script"
Execute on: select "Zabbix agent" and command "sudo / root/test.sh"
# the account that executes the command is a zabbix account, not a root account. Not using the sudo command will cause the command not to take effect after execution.
# it should also be noted that we have tried to use a specific command instead of a script, and the result is that the command is executed but does not take effect, because there is no specific failure log and the reason cannot be analyzed
# use default values for the rest. Click "Add", as shown below:
4. Remote command script
# Editing the command script according to the path of the command script defined in step 3; [root@localhost ~] # vim test.shrunkash Binder PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH# here simply think that the third login tty is pts/2 pkill-kill-t pts/2 [root@localhost ~] # chmod 764 test.sh
5. Configure sudo
# grant the zabbix account sudo the permission to execute commands without a password. For security, you can define the last "ALL" as a specific command; # or modify the script owner to zabbix in step 4 and have the permission to execute, but note that the script placement directory opens executable permissions or even writeable permissions to the zabbix account, so that the script in step 3 does not need to be granted by sudo [root@localhost ~] # visudo
Zabbix ALL=NOPASSWD: ALL
6. Verification
Remotely log in to the third tty of the host, do not do any other action under the CLI, trigger the trigger threshold, trigger the command action to force the third login user to go offline.
As can be seen from the screenshot, when the online user exceeds the threshold, the trigger state of "PROBLEM" only lasts for about 1 minute, that is, it returns to the "OK" state, indicating that the script command forcing the third user to go offline has been executed and executed successfully.
It can also be seen from the historical data of "Number of logged in users" Item that when trigger is triggered, the third logged-in user is logged off.
Under the third tty logged in, you can see that the connection is interrupted by the host (showing the local time, which deviates from the host time shown in the figure above).
Summary
So far, this is the end of this article on Zabbix remote execution commands. For more information about Zabbix remote execution commands, please search the previous articles or continue to browse the relevant articles below. I hope you will support me in the future!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.