1. Install the MySQLdb module; #!/bin/bash#this is rpm python environment depends onfunction depends_rpm () {yum-all yum-y install G cc* python-devel python-pip mariadb mariadb-devel mariadb-serverif [$?-eq 0] then pip install mysql-python==1.2. 5 Else echo "Environmental initialization Failure" fi}depends_rpm
2.python Installing the zabbix4.0 script;#!/bin/evn python import subprocessimport osimport SHUTILIMPORT URLLIB2IMPORT MYSQLDBDEF DOANLOAD_ZABBIX_RPM (): print (" downloading with zabbix-3.5.1 ") url = " http://repo.zabbix.com/ zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm " f = Urllib2.urlopen (URL) data = f.read () path = "/usr/local/src/zabbix-release-3.5-1.el7.noarch.rpm" with Open ("Path", "WB") as code: code.write ( Data) os.system (' rpm -vih ' path ') Def zabbix_package_ Install (): subprocess.call ("Yum -y install zabbix-get zabbix-sender zabbix-web zabbix-agent zabbix-web-mysql zabbix-server-mysql ", shell=true) os.system (' systemctl Restart mariadb.service ') os.system (' Mysqladmin -u root password mysqladmin ') Try: subprocess.check_call ("Yum -y install zabbix-get zabbix-sender zabbix-web zabbix-agent zabbix-web-mysql zabbix-server-mysql ", Shell=true) except subprocess. Calledprocesserror as err: print ("Install rpm error check command or network ") Def zabbix_createdb (): conn = MySQLdb.connect ( host= ' localhost ', port=3306, user= ' Root ', passwd= ' Mysqladmin ',) cursor = Conn.cUrsor () cursor.execute (' Create database if not exists zabbix character set utf8 collate utf8_bin; ') sql = "" "grant all on zabbix.* to ' Zabbix ' @ ' localhost ' identified by ' 123456 ';flush privileges; "" " os.system ('/usr/bin/zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz |mysql -uzabbix -p123456 zabbix ') try: cursor.execute (SQL) print ("zabbix database Create successful ") except: print (" zabbix db grant Successful ") Def create_config (): flist={' LogFile ': '/var/log/ Zabbix/zabbix_server.log ', ' logfilesize ': 0, ' pidfile ': '/var/run/zabbix/zabbix_server.pid ', ' DBName ': ' Zabbix ', ' DBUser ': ' Zabbix ', ' Dbpassword ' : 123456, ' dbsocket ': '/var/lib/mysql/mysql.sock ', ' snmptrapperfile ': '/var/log/snmptrap/snmptrap.log ', ' Timeout ': 4, ' Alertscriptspath ': '/usr/lib/zabbix/alertscripts ', ' externalscripts ': '/usr/lib/zabbix/externalscripts ', ' Logslowqueries ': ' } confdir = "/etc/ Zabbix " if os.path.exists (confdir) == True: f = open ("/etc/ Zabbix/zabbix_server.conf ", " "WB") Os.chdir (Confdir)       &NBSp; shutil.copyfile ("zabbix_server.conf", "Zabbix_server.conf.bak") print ("backup zabbix config file sucessful") for k,v in flist.items (): flist[k]= ' = ' +str (v) f.write (k+flist[k]+ ' \ n ') print (" Zabbix-server config edit sucessful ") F.close () os.system ("sed -i '/timezone/c php_value date.timezone asia/shanghai ' /etc/httpd/conf.d/zabbix.conf ') else: print ("Zabbix configuser not exsits") def service_manager (): serlist = [ "systemctl Enable httpd.service "," Systemctl enable zabbix-server.service ", "Systemctl enable zabbix-agent.service", "Systemctl enable mariadb.service", "SystEmctl restart httpd.service "," Systemctl restart zabbix-server.service "," systemctl Restart zabbix-agent ", "Systemctl stop firewalld", "setenforce 0" ] for x in serlist: os.system (x) print ("service add and start success") def access_zabbix (): address = ("you can access http://$ServerIP/zabbix to configure your web zabbix ", " Database_user:zabbix "," Password : 123456 ", "Webui-user:admin", "Webui-password:zabbix") for i in address: print (i) return i          DOANLOAD_ZABBIX_RPM () Zabbix_package_install () Zabbix_ Createdb () Create_config () Service_manager () Web=access_zabbix () print (web)
Python Install zabbix.4.0