Python语言 install zabbix.4.0
小标 2018-09-13 来源 : 阅读 755 评论 0

摘要:本文主要向大家介绍了Python语言 install zabbix.4.0,通过具体的内容向大家展示,希望对大家学习Python语言有所帮助。

本文主要向大家介绍了Python语言 install zabbix.4.0,通过具体的内容向大家展示,希望对大家学习Python语言有所帮助。

1.安装 MySQLdb 模块;#!/bin/bash
#this is rpm python Environment depends on
function depends_rpm(){
yum clean all 
yum -y install gcc* python-devel python-pip mariadb mariadb-devel mariadb-server
if [ $? -eq 0 ]
  then
       pip install MySQL-python==1.2.5     
else
       echo "Environmental initialization failure"  
fi
}
depends_rpm#安装zabbix4.0 脚本;
import subprocess
import os
import shutil
import urllib2
import MySQLdb
def Doanload_zabbix_rpm():
    print("downloading with zabbix-3.5.1")
    url = "//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':'3000' 
               }     
      confdir = "/etc/zabbix"
      if os.path.exists(confdir) == True:       
         f = open("/etc/zabbix/zabbix_server.conf", "wb")   
         os.chdir(confdir)
         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 //$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的相关知识,希望对Python有兴趣的朋友有所帮助。了解更多内容,请关注职坐标编程语言Python频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 1 不喜欢 | 0
看完这篇文章有何感觉?已经有1人表态,100%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程