Update Template BGP Huawei
This commit is contained in:
parent
e543d769f8
commit
fdb93315a7
25
templates/bgp/README.md
Normal file
25
templates/bgp/README.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# BGP Peers
|
||||||
|
|
||||||
|
## Changelog:
|
||||||
|
- Nome das sessões BGP baseados na organizacao vinculada ao ASN;
|
||||||
|
- Descobertas personalizadas com scripts python e shell;
|
||||||
|
- Alertas atualizados com o nome da sessao.
|
||||||
|
|
||||||
|
## Instalação
|
||||||
|
- Importar os templates;
|
||||||
|
- Copiar os Scripts e ajustar as permissões.
|
||||||
|
|
||||||
|
### Huawei
|
||||||
|
Copiar os scritps para:
|
||||||
|
```
|
||||||
|
/usr/lib/zabbix/externalscripts
|
||||||
|
```
|
||||||
|
Ajustar Permissões:
|
||||||
|
```
|
||||||
|
chmod +x /usr/lib/zabbix/externalscripts/discovery_bgp_peers_hw.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Teste do script
|
||||||
|
```
|
||||||
|
python3 discovery_bgp_peers_hw.py <ip> <community> <porta>
|
||||||
|
```
|
||||||
64
templates/bgp/discovery_bgp_peers_hw.py
Normal file
64
templates/bgp/discovery_bgp_peers_hw.py
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
try:
|
||||||
|
ip = sys.argv[1]
|
||||||
|
community = sys.argv[2]
|
||||||
|
porta = sys.argv[3]
|
||||||
|
except:
|
||||||
|
print('\n')
|
||||||
|
print(' Dicovery BGP Peer Huawei')
|
||||||
|
print(' by IPv0')
|
||||||
|
print(' ---')
|
||||||
|
print(' Use: python3 discovery_bgp_peers_hw.py <ip> <community> <porta>')
|
||||||
|
print('\n')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
# Criando saida do walk com os asns
|
||||||
|
saida_asns = subprocess.check_output(f'snmpwalk -On -v2c -c {community} {ip}:{porta} .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.2.0', shell=True).decode()
|
||||||
|
|
||||||
|
# Criando saida do walk com os peers
|
||||||
|
saida_peers = subprocess.check_output(f'snmpwalk -On -v2c -c {community} {ip}:{porta} .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.4.0', shell=True).decode()
|
||||||
|
|
||||||
|
# Criando lista de ASN e index
|
||||||
|
lista_asns_index = re.findall(r'\.1\.3\.6\.1\.4\.1\.2011\.5\.25\.177\.1\.1\.2\.1\.2\.0\.([0-9\.]+)\s=\sGauge32:\s([0-9]+)', saida_asns)
|
||||||
|
|
||||||
|
# Criando lista de ASN
|
||||||
|
lista_asns = []
|
||||||
|
for asn in lista_asns_index:
|
||||||
|
if asn:
|
||||||
|
lista_asns.append(asn[1])
|
||||||
|
|
||||||
|
lista_asnames = []
|
||||||
|
|
||||||
|
# Criando lista com o nome dos ASNs
|
||||||
|
for asn in lista_asns:
|
||||||
|
var = subprocess.check_output(f'whois -h whois.cymru.com "AS{asn}" | grep -v "AS Name" | awk -F", " "'"{print $2}"'"', shell=True).decode()
|
||||||
|
lista_asnames.append(var.strip())
|
||||||
|
|
||||||
|
# Criando listas de peers e index
|
||||||
|
lista_peers_index = re.sub(r'\"', '', saida_peers)
|
||||||
|
lista_peers_index = re.findall(r'\.1\.3\.6\.1\.4\.1\.2011\.5\.25\.177\.1\.1\.2\.1\.4\.0\.([0-9\.]+)\s=\sSTRING:\s([0-9A-Za-z\.\:]+)', lista_peers_index)
|
||||||
|
|
||||||
|
# Justando listas
|
||||||
|
lista_zip = zip(lista_asns_index, lista_peers_index, lista_asnames)
|
||||||
|
|
||||||
|
lista_peers_bgp = []
|
||||||
|
|
||||||
|
for i in lista_zip:
|
||||||
|
if i[0][0] == i[1][0]:
|
||||||
|
dic = {
|
||||||
|
"{#SNMPINDEX}": i[0][0],
|
||||||
|
"{#BGPPEER}": i[1][1],
|
||||||
|
"{#ASNUM}": i[0][1],
|
||||||
|
"{#PEERNAME}": i[2]
|
||||||
|
}
|
||||||
|
|
||||||
|
lista_peers_bgp.append(dic)
|
||||||
|
|
||||||
|
saida_json = json.dumps(lista_peers_bgp, indent=2)
|
||||||
|
print(saida_json)
|
||||||
Loading…
x
Reference in New Issue
Block a user