Zabbix Agent Shell One-click installation script

Source: Internet
Author: User

#!/bin/Bashbasepath=$ (CD 'dirname$0`;pwd) Shell_dir="${basepath}/shell"Package_dir="${basepath}/package"#获取参数 whileGetopts"I:"Opt Do     Case$optinchi) ipaddr=$OPTARG;; \?)            ;; Esac DoneEcho "IP NO:"Echo$ipaddrrpm-IVH $PACKAGE _dir/zabbix-release-2.4-1. el6.noarch.rpmYum Install-Y zabbix-Agentif[-e/etc/zabbix/zabbix_agentd.conf]; ThenEchoEcho "######### #begin Modify zabbix_agentd.conf##########"sed-I.'s/^server=127.0.0.1/server=116.*******28/g'/etc/zabbix/zabbix_agentd.confsed-I.'s/^serveractive=127.0.0.1/serveractive=116.*******.28/g'/etc/zabbix/zabbix_agentd.confsed-I."S/hostname=zabbix server/hostname=${ipaddr}/g"/etc/zabbix/zabbix_agentd.conf#sed-I.'S/^hostname=zabbix server/hostname= $ip/g'/etc/zabbix/zabbix_agentd.conf#sed-I.'/listenport=10050$/a\listenport=21224'/etc/zabbix/zabbix_agentd.conf#sed-I."/listenip=0.0.0.0$/a\listenip=${ip}"/etc/zabbix/zabbix_agentd.confsed-I.'/timeout=3$/a\timeout=30'/etc/zabbix/zabbix_agentd.confgrep-V'^#'/etc/zabbix/zabbix_agentd.conf |grep-V'^$'Echo "######### #end Modify zabbix_agentd.conf##########"EchoElseEchoEcho "######### #zabbix_agentd. conf is not exit##########"EchoExit2fiif[-D/ETC/ZABBIX/ZABBIX_AGENTD.D]; ThenCP-R $PACKAGE _dir/yuwang.conf/etc/zabbix/Zabbix_agentd.dElseEcho "##########/etc/zabbix/zabbix_agentd.d is not exist##########"EchoExit3fiEcho "######### #begin Move Scripts to/etc/zabbix/scripts##########"if[-d/etc/zabbix/scripts]; Then    CP-R $PACKAGE _dir/scripts/*/etc/zabbix/scripts chmod +x/etc/zabbix/scripts/*else mkdir/etc/zabbix/scripts cp-r $PACKAGE _dir/scripts/ */etc/zabbix/scripts chmod +x/etc/zabbix/scripts/*fiecho "######### #end Move Scripts to/etc/zabbix/scripts########## "echo" ######### #begin modify/etc/sudoers########## "Sed-i ' s/\ (defaults.*requiretty\)/#\1/g '/etc/sudoersecho ' ... ' Sed-i ' s/!visiblepw/visiblepw/g '/etc/sudoersecho ' ... ' echo ' Zabbix all= (All) nopasswd:/etc/zabbix/scripts/* ' > >/etc/sudoersecho ' ... ' echo ' ######### #end modify/etc/sudoers########## "service zabbix-agent Restartchkconfig      Zabbix-agent onzabbixagentpid= ' PS aux|grep zabbix_agentd|grep-v "grep" |awk ' {print $} ' if ["$zabbixagentpid"];then echo "Success! Zabbix agent is running now "fi

Configuration file Contents Cat yuwang.conf userparameter=iostat[*],/etc/zabbix/scripts/iostat. SH $1 $2userparameter=discovery.disk,/etc/zabbix/scripts/discovery.disk. SH userparameter=net. if. discovery2,/etc/zabbix/scripts/net. if. Discovery2. SH

script NIC discovery, disk IO monitoring, network card traffic monitoring [[email protected]-scripts]#CatDiscovery.disk.SH #!/bin/Bashcount=`Cat/proc/diskstats |grep '[Vs]d[a-z]'|WC-l ' I=1Echo '{'Echo '"Data": [' forDiskinch`Cat/proc/diskstats |grep '[Vs]d[a-z]'|awk '{print $}'` Do        if[$i-lt $count]; Then                Echo '{"{#DISK}": "'$disk'"},'        Else                Echo '{"{#DISK}": "'$disk'"}'        fiI=`Echo$ (($i +1))` DoneEcho '    ]'Echo '}'[[Email protected]-scripts]#CatIostat.SH #!/bin/Bashresult= ' Iostat-k-x $1 1 2|grep$1|Tail-N1 ' #Echo "$result"#Device: RRQM/s wrqm/s r/sW/s rkb/s wkb/s avgrq-sz Avgqu-sz await SVCTM%UTIL#SDA0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00functionreadkb () {Echo "$result"|awk '{print $6}'}functionwritekb () {Echo "$result"|awk '{print $7}'}functionavgrq-sz () {Echo "$result"|awk '{print $8}'}functionavgqu-sz () {Echo "$result"|awk '{print $9}'}functionawait () {Echo "$result"|awk '{print $}'}functionSVCTM () {Echo "$result"|awk '{print $11}'}functionutil () {Echo "$result"|awk '{print $}'}$2[email protected] scripts]#CatNet.if. Discovery2.SH #/bin/Bashi=0names=() forInterfaceinch`Cat/proc/net/dev |Tail-N +3|grep-V'lo\|vir\|vnet'|grep-op'\w+\d* (? =:)'`# forInterfaceinch`Cat/proc/net/dev |Tail-N +3|grep-V'Lo'|grep-op'\w+\d* (? =:)'` DoC=`ifconfig$interface2>/dev/NULL|grep 'inet'|grep-v-c'127.0.0.1'`    if[$c-GT0]; Thennames[$i]=$interface i=`Echo$ ((i+1))`    fi Donelength=${#names [*]}i=1Echo '{'Echo '"Data": [' forInterfaceinch${names[*]} Do    if[$i-lt $length]; Then        Echo '{"{#IFNAME}": "'$interface'"},'I=`Echo$ ((i+1))`    Else        Echo '{"{#IFNAME}": "'$interface'"}' Breakfi DoneEcho '    ]'Echo '}'

Zabbix Agent Shell One-click installation script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.