python install zabbix.4.0

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

2.python 安装zabbix4.0 脚本;
#!/bin/evn python 
import subprocess
import os
import shutil
import urllib2
import MySQLdb
def 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':'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 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)

原文地址:http://blog.51cto.com/breaklinux/2065435

时间: 2024-08-15 21:39:13

python install zabbix.4.0的相关文章

Pyhon install zabbix 4.0

1.安装 MySQLdb 模块;#!/bin/bash#this is rpm python Environment depends onfunction depends_rpm(){yum clean all yum -y install gcc* python-devel python-pip mariadb mariadb-devel mariadb-serverif [ $? -eq 0 ] thenpip install MySQL-python==1.2.5 elseecho "En

Zabbix 4.0.4 install for Centos 7

警告:磁盘分区时使用 LVM卷等 不负责任何责任,本人使用的是基本磁盘卷 /+swap 1. 部署LAMP环境 a. 由于zabbix提供集中的web监控管理界面,因此服务在web界面的呈现需要LAMP架构支持. yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhas lrzsz nano b.

深入浅出Zabbix 3.0 -- 第十五章 Zabbix 协议与API

今天是六.一儿童节,祝小朋友们节日快乐!发完此文就带我家小朋友出去玩耍了. 第十五章 Zabbix 协议与API 本章将介绍和开发相关的Zabbix协议和API的内容,通过对Zabbix协议和API的深入了解,你可以利用Zabbix协议编写客户端程序并将其嵌入的产品或系统中,并将数据发送到Zabbix server,这在无法安装Zabbixagent等程序的场景(例如专用的嵌入式系统)中非常有用.你也可以利用Zabbix API开发自己的业务系统,或灵活的与现有系统整合集成. 15.1 Zabb

CentOS 7 安装 Zabbix 3.0

CentOS7搭建Zabbix 一.安装数据库: 1.  安装数据库:sudo  yum  grouinstall mariadb mariadb-server –y 2.  启动数据库:sudo systemctl  start mariadb 3.  设置开机启动:sudo systemctl enable mariadb 4.  初始化数据库:sudo mysql_secure_installation            //设置密码为123456 二.安装Zabbix 1.  下载Z

Zabbix 3.0 部署监控 [三]

Zabbix 3.0 部署监控 [三] zabbix 时间:2016年9月22日 笔者QQ:381493251 Abcdocker交流群:454666672 如果遇到什么问题可以进群询问,我们是一个乐于帮助的集体! Dashboard首页信息介绍 Status of Zabbix(Zabbix状态)介绍 Zabbix server is running                           #Zabbix服务器是否运行 Number of hosts (enabled/disabl

zabbix 3.0 on centos 7

yum install httpd httpd-develyum -y install mariadb*yum install php php-cli php-common php-devel php-pear php-gd php-mbstring php-mysql php-xml systemctl start mariadb.service systemctl enable mariadb.servicehttp://blog.csdn.net/default7/article/deta

CentOS6上编译安装ZABBIX 3.0

0x00  实验环境 系统:CentOS-6.8-x86_64 httpd:2.4.20 mysql:5.6.31 php:5.6.22 IP:10.0.0.4 0x01  编译安装zabbix3.0 1.下载zabbix源码包 [[email protected] src]# cd /usr/local/src/ [[email protected] src]# wget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Late

Zabbix 3.0 监控MySQL

Mysql监控  zabbix自带了一个监控mysql的模板,但是真正监控mysql的并不是zabbix自带的模板.而是percona公司的一个监控mysql模板  percona官网: www.percona.com Percona组成介绍 1.php脚本    用来数据采集 2.shell脚本  用来调用采集信息 3.zabbix配置文件 4.zabbix模板文件 安装文档:https://www.percona.com/doc/percona-monitoring-plugins/LATE

zabbix 3.0快速安装简介

zabbix快速安装 系统版本:centos 7 通过yum方法安装Zabbix3.0,安装源为阿里云 yum源配置 rpm -ivh http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm 安装 yum install zabbix-server zabbix-agent zabbix-web zabbix-server-mysql zabbix-web-mysq