zabbix自動發現監控腳本

自動發現端口列表腳本

# -*- 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

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/535293.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/535293.shtml
英文地址,請注明出處:http://en.pswp.cn/news/535293.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

獲取cpu使用率腳本

#!/bin/bash # 獲取要監控的本地服務器IP地址 IPifconfig | grep inet | grep -vE inet6|127.0.0.1 | awk {print $2} echo -e "\033[32mIP地址&#xff1a;\033[0m" $IP echo -e "\033[31m獲取CPU\033[0m" # 獲取cpu總核數 cpu_numgrep -c "model n…

獲取磁盤使用率

#!/bin/bash #用途&#xff1a;監控磁盤的使用情況。 #定義檢查磁盤的空間使用率函數 userroot topnum10 local_diskdir/data/jiankong/disk mkdirdisk() { if [ ! -d $disktmpdir ];then mkdir $disktmpdir fi } chk_sp() {ip$1n$(wc -l $local_diskdir/$ip/chk_sp.log | awk …

python郵件腳本

#用于發送測試報告(帶附件)或其它內容# -*- coding:utf-8 -*- import os import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipartclass SendEmail(object):def __init__(self, receivers):mail_host "127.0.0.1" # …

Rsync+Inotify

RsyncInotify Rsync這個一般使用系統自帶的服務&#xff0c;服務端需要啟動客戶端無需啟動&#xff0c;服務端設置開機自動啟動 systemctl start rsyncd systemctl status rsyncd systemctl restart rsyncd systemctl enable rsyncd Inotify單獨下載安裝&#xff0c…

logstash密碼設置步驟

生成密鑰存儲倉庫 cd /app/logstash-6.8.4/bin/ ./logstash-keystore create 輸入y 添加Logstash中可引用的變量 ./logstash-keystore add es_user 輸入elastic ./logstash-keystore add es_pwd 輸入bamBoo123 ./logstash-keystore add kafka_pwd 輸入bamBoo123 ./logstash…

清理cacahe腳本

#! /bin/bash # 需要釋放內存的&#xff0c;內存使用百分比&#xff0c;可以傳參&#xff0c;默認是85% max_rate$1 if [ ! "$max_rate" ] ; thenmax_rate85 fi echo "max_rate: $max_rate"totalfree -m | awk NR2 | awk {print $2} usedfree -m | awk NR2…

Prometheus node_exporter 指標說明及告警規則表達

Prometheus node_exporter 指標說明及告警規則表達_獨步秋風的博客-CSDN博客_node exporter 指標

UnicodeEncodeError: 'gbk' codec can't encode character '\xeb' in position 20: illegal multibyte sequ

源代碼&#xff1a;with open (os.path.join(self.root,filename),mode‘w’,newline’’) as f: writercsv.writer(f) for img in images: nameimg.split(os.sep)[-2] labelself.name2lable[name] writer.writerow([img,label]) 解決方法 在open&#xff08;&#xff09;里面…

列表生成式(List)

列表生成式即List Comprehensions&#xff0c;是Python內置的非常簡單卻強大的可以用來創建list的生成式。 list(range(1,6)) [1,2,3,4,5]print([x*x for x in range(10)]) [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]print([x*x for x in range(10) if x%20]) [0, 4, 16, 36, 64]

uint8 轉換為 float

znp.arange(3,dtypenp.uintj8) >>> z.astype(float) array([ 0., 1., 2.]) >>> np.int8(z) array([0, 1, 2], dtypeint8)

AttributeError: 'NoneType' object has no attribute 'astype'

img cv2.imread(path)#path為圖片地址 print(type(img))>>> <class numpy.ndarray> <class numpy.ndarray> <class numpy.ndarray> <class NoneType>錯誤問題為沒有正確讀到圖片&#xff0c;返回一個Nonetype類型&#xff0c;

pycharm 自動補全括號 引號

過程&#xff1a; File->settings->Editior->General->Smart Keys 勾選Insert paired barckets(),[],{},<>

RuntimeError: freeze_support()

train_dataloaderDataLoader(train_dataset,batch_sizebatch_size,shuffleTrue,num_workers4) 把nu_worker4 去掉 train_dataloaderDataLoader(train_dataset,batch_sizebatch_size,shuffleTrue)

IndexError: list index out of range image_name=self.images_name[index]

這里是引用 def __len__(self):return len(self.images_name) 注意這個地方

NameError: name 'long' is not defined

是因為高版本Python3.x中沒有long類型&#xff0c;只有int類型。 Python2.x中既有long 類型又有int 類型。 所以只需要把long()改為int 就行

Latex 修改公式的的大小

第一種方法&#xff1a;用比較笨的方法&#xff0c;一個一個公式用\begin{small} \begin{equation} \ldots \end{equation} \end{small} 第二種方法&#xff1a;定義新的變量環境 在開始\newenvironment{sequation}{\begin{equation}\small}{\end{equation}}演示代碼&#xff1…

latex表格名的引用問題

##方法 \begin{table} \label{*****} \end{table} 在文章中加入Tab.~\ref{****} 如果沒有顯示出來的話 在文章的開頭加上\usepackage{table}

Anaconda如何重新在開始菜單顯示

步驟&#xff1a; &#xff08;1&#xff09; win R &#xff0c;然后輸入Cmd 進入電腦命令端 &#xff08;2&#xff09;cd 進入anaconda 安裝的路徑&#xff0c;然后 輸入 、、、 python .\Lib_nsis.py mkmenus 、、、 然后就OK了

python 讀取 Excel 文件的方法 csv.reader

with open(./hotel_bookings.csv,newline) as f:readercsv.reader(f)for row in reader:print(row)row 為list 類型