FIBERHOME – NAGIOS PLUGIN – CHECANDO STATUS DE PORTAS PON

Share Button

English Title: Fiberhome – Nagios Plugin – checking pon status

Recentemente re-escrevi o plugin usando SNMP que realiza leituras em OLTs da Fiberhome e indica se uma determinada porta PON possui ONUs conectadas.

O legal é poder integrar isso ao nagios ou a outros sistemas de monitoramento e conseguir receber avisos de um rompimento ou defeito na porta de maneira automática.

https://github.com/jorgeluiztaioque/check_pon_fiberhome

#!/usr/bin/python
#-----------------------------------------------------------------------
# Nagios check PON in OLT Fiberhome
# Written by Jorge Luiz Taioque
# This plugin check status of all ONUs connected in a specific PON 
# and return if these ONUs operational state is UP or DOWN
#
# ----
# -----
# Usage:
# ./check_pon_fiberhome [IP_OLT] [PON_SLOT/PON_PORT]
# Like:
# ./check_pon_fiberhome 10.10.10.1 1/8
# put only the slot_number and pon_number before and after slash /
#
#
# In nagios service.cfg use:
# check_command:	check_pon_fiberhome!10.10.10.1!1/8
#-----------------------------------------------------------------------

__author__ = 'Jorge Luiz Taioque'
__version__= 0.1

import os
import commands
import netsnmp
import sys

olt_ip = sys.argv[1]
olt_port = sys.argv[2]

pon_name = commands.getoutput("snmpwalk -Os -c adsl -v 1 "+olt_ip+" 1.3.6.1.4.1.5875.800.3.9.3.4.1.2")

pon_name_list =  pon_name.split()

indices = 0
for i, elem in enumerate(pon_name_list):
	if olt_port in elem:
		indice = i

mib =  pon_name_list[indice-4]
mib_port = mib[-9:]

mib_status = "1.3.6.1.4.1.5875.800.3.9.3.4.1.5"

readport = commands.getoutput("snmpwalk -Os -c adsl -v 1 "+olt_ip+" "+mib_status+"."+mib_port+"")

status = readport[-1:]

status = int(status)

if status == 0:
        print 'PON is Down'
        sys.exit(2)

if  status == 1:
        print 'PON is Up'
        sys.exit(0)

	

Automatizando Backup de OLTs Fiberhome via terminal

Share Button

English title: Automating Backups of Fiberhome OLTs over line comand

downloadbk-olt-fiberhome.py é um simples script para automatização de backup de OLTs Fiberhome, sem a necessidade do software de gerencia ANM2000 instalado.

Usage
./bk-olt-fiberhome.py IP_ADDRESS

Configuration
Don’t forgot to configure all variables in file bk-olt-fiberhome.py
=======================================================================
user = ‘GEPON’
password = ‘GEPON’
FTPSERVER = ‘200.200.200.200’
ftpuser = ‘user’
ftppassword = ‘123456’
=======================================================================

Link para o GitHub


#!/usr/bin/python
#-------------------------------------
#by Jorge Luiz Taioque
#jorgeluiztaioque at gmail dot com
#www.networktips.com.br
#-------------------------------------
#backup OLTs and ONUs fiberhome
#Usage 
#./bk-olt-fiberhome.py IP_ADDRESS


import sys,pexpect
import getpass
import time

HOST = sys.argv[1]

#configure here all variables following you system 
#=======================================================================
user = 'GEPON'
password = 'GEPON'
FTPSERVER = '200.200.200.200'
ftpuser = 'user'
ftppassword = '123456'
#=======================================================================


child = pexpect.spawn ('telnet '+HOST) #option needs to be a list
child.timeout = 150
child.logfile = sys.stdout #display progress on screen

#loging to OLT IP
time.sleep(2)
child.expect ('Login: ') #waiting for login
child.sendline (user) #sending login name
child.expect('Password:') #waiting for password
child.sendline (password) #sending password
child.expect('>')

time.sleep(3)

#go up enable configuration
child.sendline ('EN'+'\r') #going to ENABLE configuration
child.expect('Password:') #waiting enable password
child.sendline (password) #sending enable password 
time.sleep(3)
child.expect('#')

#sending commando to copy configuration file to remote FTP server
child.sendline ('upload ftp config '+FTPSERVER+' '+ftpuser+' '+ftppassword+' bk-olt-'+HOST+'-.cfg')
time.sleep(10)

#exiting connection
child.expect('#')
child.sendline ('exit \r')
child.sendline ('exit \r')

Switch-backup.py – Script para backup de switch gerenciaveis

Share Button

English Title: switch-backup.py a script to make backup of manageable switchs.

Um simples script para automatizar a tarefa de coletar as informações de um switch e armazená-las em um servidor TFTP.

Eu utilizo a mesma estrutura de script para realizar backup em switchs, TP-Link, DELL e Cisco, bastando alterar simplesmente a sequencia que os comandos são enviados e como o copy para o servidor TFTP deve ser feito.

Esse script funciona perfeitamente nos modelos da TP-Link:
TL-SG2216
TL-SG2424

Github

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python
#Script starts here
 
 
import sys,pexpect
import getpass
import time
 
HOST = '10.10.10.1'
user = 'admin'
password = 'passworc'
TFTPSERVER = '200.200.200.200'
 
child = pexpect.spawn ('telnet '+HOST) #start telnet session in switch
child.timeout = 30
child.logfile = sys.stdout #display progress of script on screm
 
time.sleep(2)
 
child.expect ('User:') #wait user
 
child.sendline (user+'\r') #send user
 
child.expect('Password:') #wait password
 
child.sendline (password+'\r') #send password
 
child.sendline ('\r')
 
time.sleep(2)
 
child.sendline (' enable\n'+'\r') #change mode to enable mode
 
child.expect('#') #wait # enable mode
 
child.sendline ('copy startup-config tftp ip-address '+TFTPSERVER+' filename bksw-'+HOST+ '\r') #send command to upload startup-config to TFTP server
time.sleep(2)
 
child.sendline ('logout \r') #exit switch console

remotessh.py Script em python para executar comandos remotos via SSH

Share Button

English Title: remotessh.py script in python to execute remote commands in ssh connection.

This script is very efficient to do backups or execute many commands automatically.

Use:
python remotessh.py [host] [username] [passuord] [“shell_command”]
./remotessh.py [host] [username] [passuord] [“shell_command”]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
#!/usr/bin/python
 
import pxssh
import getpass
import sys
 
 
try:
    s = pxssh.pxssh()
    hostname = sys.argv[1]
    username = sys.argv[2]
    password = sys.argv[3]
    command = sys.argv[4]
    s.login (hostname, username, password)
    s.sendline ('uptime')
    s.prompt()
    print s.before
    s.sendline (command)
    s.prompt()
    print s.before
    s.logout()
except pxssh.ExceptionPxssh, e:
    print "pxssh failed on login."
    print str(e)

Girhub link: github remotessh

Script – Backup de VMs no XEN / XCP com Shell Script

Share Button

Esse script faz backup das VMs sem necessidade de reboot ou shutdown, permitindo um backup sem a queda do servidor.

O backup consiste em:
-Procurar cada VM pegando seu LABEL e UUID
-Criar um Snapshot
-Exportar o snapshot como uma VM .xva
-Apagar o snapshot criado

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash

#Destino onde ficara guardado o backup
dir="/mnt/usb/";
#Quantidade de cópias diárias que o backup deve permanecer na unidade.
dias=5;
 
#Pegando nomes das maquinas
uuids=$(xe vm-list is-control-domain=false is-a-snapshot=false power-state=running | grep "uuid" | awk '{ print $'5'}');
labels=$(xe vm-list is-control-domain=false is-a-snapshot=false power-state=running | grep "name-label" | awk '{ print $'4' $'5' $'6' $'7' $'8' $'9' $'10'}');
qvms=$(echo "$uuids" | wc -l);
 
#Loop para backup de cada VM
for i in `seq 1 $qvms`
do
uid=$(echo $uuids | awk '{ print $'$i'}');
label=$(echo $labels | awk '{ print $'$i'}');
 
nuid=$(xe vm-snapshot uuid=$uid new-name-label=$label-backup)
xe template-param-set is-a-template=false ha-always-run=false uuid=$nuid
xe vm-export vm=$nuid filename=$dir$label-backup.xva
xe vm-uninstall uuid=$nuid force=true
 
done
 
#Apagando arquivos mais antigos que a variável (dias)
find /mnt/usb/ -ctime +$dias -name "*.xva" -exec rm -rvf {} \;

Como importar a vm?
xe vm-import filename=nome-do-arquivo.xva sr-uuid=UUDI-DE-SEU-SR