Zabbix combines bat script and scheduled task to open window remote desktop

Scene analysis:

Xiaodong, an employee of an IT company, deployed a zabbix in the company to monitor some usage of the window system server. He now wants to achieve a function, which is to find through the browser that a certain window host has high memory, or high cpu utilization, or some warnings that some services of a certain server are down. Where can he go through the browser? Execute the script to open the remote desktop, and then he only needs to fill in the account and password of the remote host to log in to the window host that appears to troubleshoot the cause of the error. (Because Xiaodong's company mainly uses window hosts, and does not consider Linux systems for the time being)
Implementation principle
1. First, use a browser to open the host of the zabbix_web interface to install the agent. The purpose is for zabbix_server to call the scheduled task created on this host through system.run and open the remote desktop
2. Use a browser to browse the host of the zabbix_web interface to create a scheduled task to execute commands to open the remote desktop
3.zabbix Call the command to open the remote desktop of the window
(Note: I have tested that the scheduled task of the window does not seem to be able to customize the parameters. If the scheduled task cannot be passed the parameters, the IP that needs to be turned on the remote desktop cannot be obtained)

Implementation steps

Step 1: Install the agent on the window host used to browse the zabbix_web interface
Zabbix combines bat script and scheduled task to open window remote desktop

Step 2: Create two bat scripts, 1.bat and 2.bat
1. The content of the bat script is as follows
@echo off
set /pa=<C:\Users\Administrator\Desktop\ip.txt
mstsc /v:%a%
2. The content of the bat script is as follows:
echo %1>C:\Users\Administrator\Desktop\ip.txt
schtasks /run /tn test
The process of running the above script is as follows: 2.batà1.bat
explanation: zabbix
calls the command, which requires remote The ip is passed as a parameter to the 2.bat script. At this time, the ip that needs to be connected remotely will be stored in C:\Users\Administrator\Desktop\ip.txt (because the scheduled task of the window cannot be transferred, the ip must be stored locally ). Then, the 2.bat script will call the scheduled task test, which actually calls the 1.bat script. In this case, the final script is the zabbix call command, in order to execute mstsc /v: remote ip. Zabbix can directly run mstsc /v: remote ip through commands to open the remote desktop. Therefore, it is necessary to realize the function of opening the window remote desktop through zabbix+bat script + scheduled task.

The third step: Create a window scheduled task
My computer right-click management, open the task scheduler, click on the right to create a plan to
Zabbix combines bat script and scheduled task to open window remote desktop
Zabbix combines bat script and scheduled task to open window remote desktop
create a plan named test, the plan is to execute the 1.bat script
Zabbix combines bat script and scheduled task to open window remote desktop

The fourth step: zabbix call command to open the remote desktop
call mode with system.run. Because system.run can be called directly, there is no need to configure key values ​​in zabbix_agent.conf.
Zabbix combines bat script and scheduled task to open window remote desktop
The ip of the host used to browse the zabbix_web interface is 192.168.1.47.
Configure a command to open the window remote desktop
Zabbix combines bat script and scheduled task to open window remote desktop

/usr/local/zabbix/bin/zabbix_get -s 192.168.1.47 -k system.run["C:\Users\Administrator\Desktop\2.bat {HOST.IP}"]
Explanation:
Zabbix_server calls 192.168.1.47 (using The 2.bat script on the browser to browse the web host) to open the remote host. {HOST.IP} can be changed dynamically, the host computer executes this command to turn on the remote host.
Experimental verification:
Select 1.38 on 1.47 to execute the script to open the remote desktop, which can open the remote desktop of 1.38
Zabbix combines bat script and scheduled task to open window remote desktop
Zabbix combines bat script and scheduled task to open window remote desktop

The experiment was successful

Guess you like

Origin blog.51cto.com/14483703/2542576