Community discussions

MikroTik App
 
metyl
just joined
Topic Author
Posts: 9
Joined: Wed Oct 05, 2011 9:02 pm

Dude to nagios with map coordinates

Sun Jul 29, 2012 11:53 am

Script to make nagios hosts files from dude export.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys
import xml.etree.ElementTree as ET
tree = ET.parse(sys.argv[1])
root = tree.getroot()
idip={}
idnazwa={'0':'0'}
idparent ={ '0':'0' }
idcoords={}
for device in root.findall('Device'):
  id = device.find('sys-id').text
  name = device.find('sys-name').text
  addr = device.find('addresses').text
  try:
    parent = device.find('parentIDs').text
  except AttributeError:
    parent = "0"
  idip[id]=addr
  idnazwa[id]=name
  idparent[id]=parent


for element  in root.findall('NetworkMapElement'):
  try:
    itid = element.find('itemID').text
  except AttributeError:
    continue
  x = element.find('itemX').text
  y = element.find('itemY').text
  idcoords[itid]=str(x) +"," +str(y)

for idx in idip:
  #print "ip "+idip[idx] +"   nazwa " +idnazwa[idx] +" rodzic " +idnazwa[(idparent[idx])] +" pozycja " +idcoords[idx]
  f =open("./host_"+idnazwa[idx]+".cfg","w")
  f.write("define host {\n")
  f.write("\tuse host-template\n")
  f.write("\thost_name\t"+idnazwa[idx]+"\n")
  f.write("\talias\t"+idnazwa[idx]+"\n")
  f.write("\taddress\t"+idip[idx]+"\n")
  if ( idparent[idx] != "0"  ):
    f.write("\tparents\t"+idnazwa[(idparent[idx])]+"\n")
  f.write("\t2d_coords\t"+idcoords[idx]+"\n")
  f.write("\tcontact_groups\tadmins\n")
  f.write("}")
  f.close

Last edited by metyl on Sat Jun 22, 2013 8:53 pm, edited 1 time in total.
 
wildbill442
Forum Guru
Forum Guru
Posts: 1055
Joined: Wed Dec 08, 2004 7:29 am
Location: Sacramento, CA

Re: Dude to nagios with map coordinates

Sat Sep 15, 2012 1:32 am

Damn I wish I would've seen this before using nconf to manually enter 200+ devices. After I was done I thought, I should write a perl script to parse the XML backup file for the dude to import this information.

Haven't used the script yet, but nicely done.
 
metyl
just joined
Topic Author
Posts: 9
Joined: Wed Oct 05, 2011 9:02 pm

Re: Dude to nagios with map coordinates

Mon Oct 15, 2012 9:42 pm

some other weird resources :
http://somewierdthings.blogspot.com/

I'm putting there stuff I used to write some time ago

Who is online

Users browsing this forum: No registered users and 42 guests