裝完Zabbix Server後還有一大堆機器等着裝zabbix agent怎麼辦?
saltstack不會!
ansible不會!!
shell不會!!!
python也不會!!!!
那還等什麼,下載我做好的程序,配置你的賬號密碼,一鍵安裝!!!
鏈接: https://pan.baidu.com/s/1RJe-su0XFPUPCeXyR2pi1g
提取碼: w453
源碼共享
ps:小白你別看了,學不會的!!
#!/usr/bin/python3
# author wugf
import configparser
import paramiko
import platform
import os
ini = "./install_zabbix_agent.ini"
# 通過ssh協議執行命令
def ssh(host, port, user, passwd, cmd):
sshc = paramiko.SSHClient()
sshc.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
sshc.connect(hostname=host, port=port, username=user, password=passwd)
except BaseException:
print("ssh賬號密碼認證錯誤", host, port ,user ,passwd)
print("\n----remote execute command")
for command in cmd:
stdin,stdout,stderr = sshc.exec_command(command)
stdout.channel
return_code = stdout.channel.recv_exit_status()
if return_code != 0:
print("命令執行失敗 ," + command)
exit(1)
print("----done: ",command)
sshc.close()
conp = configparser.ConfigParser()
conp.read(ini, encoding = "utf-8")
sections = conp.sections()
rpm = conp["DEFAULT"]["rpm"] # zabbix agent rpm文件地址
Server = conp["DEFAULT"]["Server"] # zabbix server的地址
conf = conp["DEFAULT"]["conf"] # zabbix_agentd.conf文件的地址
# 安裝zabbix_agent命令
cmd = [
"yum remove zabbix* -y",
"rpm -ivh " + rpm,
"sed -i '1,$s/^Server=.*/Server=" + Server + "/' " + conf,
"更改zabbix_agent Hostname",
"systemctl enable zabbix-agent",
"systemctl start zabbix-agent"
]
for section in sections:
Hostname = section # zabbix_agent Hostname
cmd[3] = "sed -i '1,$s/^Hostname=.*/Hostname=" + Hostname + "/' " + conf
host = conp.get(section, "host")
port = int(conp.get(section, "port"))
user = conp.get(section, "user")
passwd = conp.get(section, "passwd")
ssh(host, port, user, passwd, cmd)
win = "Windows"
if win in platform.platform():
os.system("pause")
源碼共享
ps:小白你別看了,學不會的!!
#!/usr/bin/python3
# author wugf
import configparser
import paramiko
import platform
import os
ini = "./install_zabbix_agent.ini"
# 通過ssh協議執行命令
def ssh(host, port, user, passwd, cmd):
sshc = paramiko.SSHClient()
sshc.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
sshc.connect(hostname=host, port=port, username=user, password=passwd)
except BaseException:
print("ssh賬號密碼認證錯誤", host, port ,user ,passwd)
print("\n----remote execute command")
for command in cmd:
stdin,stdout,stderr = sshc.exec_command(command)
stdout.channel
return_code = stdout.channel.recv_exit_status()
if return_code != 0:
print("命令執行失敗 ," + command)
exit(1)
print("----done: ",command)
sshc.close()
conp = configparser.ConfigParser()
conp.read(ini, encoding = "utf-8")
sections = conp.sections()
rpm = conp["DEFAULT"]["rpm"] # zabbix agent rpm文件地址
Server = conp["DEFAULT"]["Server"] # zabbix server的地址
conf = conp["DEFAULT"]["conf"] # zabbix_agentd.conf文件的地址
# 安裝zabbix_agent命令
cmd = [
"yum remove zabbix* -y",
"rpm -ivh " + rpm,
"sed -i '1,$s/^Server=.*/Server=" + Server + "/' " + conf,
"更改zabbix_agent Hostname",
"systemctl enable zabbix-agent",
"systemctl start zabbix-agent"
]
for section in sections:
Hostname = section # zabbix_agent Hostname
cmd[3] = "sed -i '1,$s/^Hostname=.*/Hostname=" + Hostname + "/' " + conf
host = conp.get(section, "host")
port = int(conp.get(section, "port"))
user = conp.get(section, "user")
passwd = conp.get(section, "passwd")
ssh(host, port, user, passwd, cmd)
win = "Windows"
if win in platform.platform():
os.system("pause")