自动发现端口列表脚本
# -*- coding: utf-8 -*-
import os
import json
data={}
tcp_list=[]
port_list=[]
command=os.popen("ss -4tln | awk -F '[ :]+' 'NR>=2{print $5}'")
for port in command:port_list.append(port.strip())
for port in port_list:port_dict={}port_dict["{#TCP_PORT}"]=port tcp_list.append (port_dict)
data["data"]=tcp_list
js1=json.dumps(data,sort_keys=True,indent=4)print (js1)
#!/bin/bash
#----将需要添加的服务器ip配置到列表
#----只需要运行此脚本即可 -
#-和其他服务器需要免密登陆
#-------
shdir=$(cd `dirname $0`; pwd)
echo $shdir
server_ip=(172.16.20.118)
zabbix_agent_dir=/usr/local/zabbix
#agent端使用端口号默认22
port_romote=22
agent_start_user=root
#agent端运行的脚本
cunstom_sh=$shdir/conf/service.sh
key_sh=$shdir/conf/service_check.sh
#处理agent配置文件的脚本
remote_sh=$shdir/conf/config.sh
#自定义配置选项的配置文件
cunstom_conf=$shdir/conf/userparameter_service.conf
stop_agent(){for ip in ${server_ip[*]};dossh -p${port_romote} root@$ip -C "systemctl stop zabbix"done
}
scp_conf(){for ip in ${server_ip[*]};doscp -r -P${port_romote} $key_sh root@$ip:$zabbix_agent_dir/conf/zabbix_agentdscp -r -P${port_romote} $cunstom_sh root@$ip:$zabbix_agent_dir/conf/zabbix_agentdscp -r -P${port_romote} $cunstom_conf root@$ip:$zabbix_agent_dir/conf/zabbix_agentdscp -r -P${port_romote} $remote_sh root@$ip:$zabbix_agent_dir/confssh -p${port_romote} root@$ip -C "source $zabbix_agent_dir/conf/config.sh $agent_start_user $zabbix_agent_dir"done
}
star_agent(){
for ip in ${server_ip[*]};dossh -p${port_romote} root@$ip -C 'systemctl restart zabbix'done
}
#stop_agent
scp_conf
star_agent#!/bin/bash
shdir=$(cd `dirname $0`; pwd)
temfile=/tmp/service.txt
#echo $shdir
service_name=(*)
zabbix_json(){length1=0length1=`cat /tmp/service.txt|wc -l`# echo $length1i=0printf "{\n"printf '\t'"\"data\":["while read line doi=$[i+1]printf '\n\t\t{'printf "\"{#SERVICE}\":\"$line\"}"if [ $i -lt $[$length1] ];thenprintf ',' fidone <$temfileprintf "\n\t\t]\n"printf "}\n"
}
check(){length=${#service_name[@]}>/tmp/service.txtfor ((i=0;i<$length;i++))do#echo $isystemctl list-units --type=service --no-pager | grep ".service"|grep ${service_name[$i]}.service>/dev/nullif [ $? -eq 0 ];thenecho ${service_name[$i]}>>$temfilefidone
}
check
zabbix_json
#rm -rf $temfile#!/bin/bash
#----将需要添加的服务器ip配置到列表
#----只需要运行此脚本即可 -
#-和其他服务器需要免密登陆
#-------
shdir=$(cd `dirname $0`; pwd)
check(){servicename=$1parameter=$2if [ $parameter == "start" ];thensystemctl list-unit-files --type=service --state=enabled --no-pager | grep ".service"|grep $servicename.service>/dev/nullif [ $? -eq 0 ];thenecho "${servicename}-startup:auto"elseecho "${servicename}-startup:no"fielsesystemctl list-unit-files --type=service --state=running --no-pager | grep ".service"|grep $servicename.service/dev/nullif [ $? -eq 0 ];thenecho "${servicename}-running"elseecho "${servicename}-no running"fifi
}
check $1 $2
#coding:utf-8
try:import json
except:import simplejson as jsonimport commands(status, output) = commands.getstatusoutput('''cat /proc/diskstats |awk '{print $3}'|egrep 'sd|vd|hd'|egrep -v '[0-9]'|sort -u''')
if output:outputs = output.split('\n')disks = []for disk in outputs:disks += [{'{#DISKONE}': disk}]print json.dumps({'data':disks},sort_keys=True,indent=4)
else:print 'discovery error'#!/bin/sh
# 8 0 sda 76880282531 8117316 937263519846 4237854729 62989000438 35668103347 777694636224 1190396494 3 2895102137 899093508
while getopts "d:o:" opt
docase $opt ind ) disk=$OPTARG;;o ) option=$OPTARG;;? )echo 'parameter is wrong!'exit 1;;esac
done
if [ ! "${disk}" ] || [ ! "${option}" ];thenecho "parameter is null" exit 1
fiif [[ ${option} == "read" ]];thencat /proc/diskstats |grep "${disk} "|awk '{print $6}'
elif [[ ${option} == "write" ]];thencat /proc/diskstats |grep "${disk} "|awk '{print $10}'
elif [[ ${option} == "readops" ]];thencat /proc/diskstats |grep "${disk} "|awk '{print $4}'
elif [[ ${option} == "writeops" ]];thencat /proc/diskstats |grep "${disk} "|awk '{print $8}'
elif [[ ${option} == "readtime" ]];thencat /proc/diskstats |grep "${disk} "|awk '{print $7}'
elif [[ ${option} == "writetime" ]];thencat /proc/diskstats |grep "${disk} "|awk '{print $11}'
fi#!/bin/bash
shdir=$(cd `dirname $0`; pwd)
agent_start_user=$1
zabbix_agent_dir=$2
echo $zabbix_agent_dir
cat $zabbix_agent_dir/conf/zabbix_agentd.conf | grep "^Include=/usr/local/zabbix/conf/zabbix_agentd/*.conf" > /dev/nullif [ $? -ne 0 ]thencat $zabbix_agent_dir/conf/zabbix_agentd.conf | grep "^Include=.*" > /dev/nullif [ $? -eq 0 ]thensed -i '/^Include=.*/d' $zabbix_agent_dir/conf/zabbix_agentd.confecho "Include= $zabbix_agent_dir/conf/zabbix_agentd/*.conf">> $zabbix_agent_dir/conf/zabbix_agentd.confelse echo "Include= $zabbix_agent_dir/conf/zabbix_agentd/*.conf">> $zabbix_agent_dir/conf/zabbix_agentd.conffi
fi
chown -R $agent_start_user:$agent_start_user $zabbix_agent_dir