#!/bin/bash
#############
#Date 2022/6/8
#mail it-arch
#############
echo "##########################################"
echo "Auto Install monitor-linux.             ##"
echo "Press Ctrl + C to cancel                ##"
echo "Any key to continue                     ##"
echo "##########################################"
read -n 1
service iptables stop
#Add firewall rules
#iptables -A INPUT -p udp --dport 161 -j ACCEPT
#/etc/init.d/iptables save
#Disabled SELINUX
sed -i "s/SELINUX=enforcing/SELINUX=disabled/"  /etc/selinux/config
setenforce 0
ifconfig | grep "inet addr" |grep -v 127.0.0.1|awk '{print $2}'|cut -d: -f2 > ip.txt
CONF=/etc/snmp/snmpd.conf
yum -y install net-snmp snmp-mibs-util net-snmp-utils unzip>/dev/null 2>&1
sleep 2
cat > $CONF << EOF
rocommunity public 127.0.0.1
rocommunity public 60.195.252.107
rocommunity public 60.195.252.110
EOF
for i in `cat ip.txt`
do
	echo "rocommunity public $i" >> $CONF
done
#echo "rocommunity public $IP">>$CONF
/etc/init.d/snmpd start
STATE=$?
if [ $? == 0 ];then
	echo "cloud-server monitor install success!"
else
	/etc/init.d/snmpd restart
fi
chkconfig snmpd on
#####################################
netstat -lntup | grep 161 |grep snmpd >/dev/null 2>&1
PORTSTAT=$?
if [ $PORTSTAT == 0 ];then
	echo "snmp is  ok!"
else
	echo "Snmp is fail!"
fi
#####################################
if [ -d /tools ];then
	cd /tools
else
	mkdir /tools && cd /tools
fi
wget -c -O /tools/jkb.zip http://it-arch.redhatxl.cn/share/linux-db4d45ec-8793-4aa2-8b46-b58d7276d205.zip
unzip jkb.zip >/dev/null 2>&1
cd /tools/jkb_agent
PATH1=`pwd`
if [ $PATH1 == /tools/jkb_agent ];then
	chmod +x st* && sh start.sh
else
	echo "jkb path is error!" && exit 0
fi
echo "Monitor install success!"
