hobbsh / icinga2-autod

Basic auto discovery for Icinga2
GNU General Public License v2.0
25 stars 9 forks source link

KeyError #1

Closed evanderv closed 9 years ago

evanderv commented 9 years ago

When I try running it looking at an individual ip or a whole subnet I get this....

Traceback (most recent call last): File "./icinga-autod.py", line 335, in main() File "./icinga-autod.py", line 127, in main v_match = vendor_match(numbers, sysobject) File "./icinga-autod.py", line 156, in vendor_match vendor_string = numbers[vendor_num] KeyError: '\r' Any ideas?

Saw this on reddit. I hope it work would be nice. Just trying out icinga2 today.

hobbsh commented 9 years ago

So the vendor_num will pull from the sysObjectID and maybe there's no data there. I don't think I accounted for that in the code. I ran into that same error testing the utility on other systems.

I'm actually just in the middle of wrapping up the fix for this. I'm curious how a \r got in there - do you mind helping me debug? Above line 127 where v_match is set, can you add a line to print the sysobject?

print sysobject
v_match = vendor_match(numbers, sysobject)
hobbsh commented 9 years ago

Just pushed some changes that might fix your problem. If it didn't I added a debug option that will print the host data out.

First, do a git pull.

Then run it with debug:

./icinga-autod.py -n NETWORK/24 -L Location -d true

Paste debug output here (delete any sensitive info like special snmp communities)

evanderv commented 9 years ago

Perfect! I will try that. Thanks

evanderv commented 9 years ago

Traceback (most recent call last): File "./icinga-autod.py", line 2, in import util.checkpkg as checkpkg ImportError: No module named util.checkpkg

hobbsh commented 9 years ago

I forgot to commit init.py for that directory. Try a git pull now and run again. Sorry about the issues.

evanderv commented 9 years ago

It's doing its thing but this was at the top...

Unknown sysObjectID prefix encountered - you can add it to the prefix list in vendor_match(), but please report this on GitHub

hobbsh commented 9 years ago

Ok that's what I thought would happen. Is it happening for all your devices or just one?

evanderv commented 9 years ago

Well I think just one in fact I don't think it actually finished, if it did it was fast. I had 89 objects.

evanderv commented 9 years ago

Shouldn't I see a file with the hosts for icinga?

hobbsh commented 9 years ago

It's because I had it exit if it encountered an unknown sysObjectID which was not very wise of me. Reworked that portion - try a git pull and run again. Thanks for hanging in there.

evanderv commented 9 years ago

OK that worked. I did it to one device that was having that problem. I will try the whole subnet again.

evanderv commented 9 years ago

Looks good. I am going to put the file in icinga and see what it looks like

hobbsh commented 9 years ago

Great. Let me know if you have any issues with it running in icinga2.

evanderv commented 9 years ago

running in icinga2? I thought I had to do this manually. Is there a way in icinga2 to run it?

hobbsh commented 9 years ago

Yes you have to manually copy it to /etc/icinga2/conf.d/ then restart icinga2. What I meant was does your instance restart successfully or give an error in /var/log/icinga2/startup.log?

evanderv commented 9 years ago

critical/config: Error: Value computed is not used. Location: /etc/icinga2/conf.d/hosts_location.conf(141): vars.location = "Location" /etc/icinga2/conf.d/hosts_location.conf(142): vars.vendor = "NSC" /etc/icinga2/conf.d/hosts_location.conf(143): vars.os == "Linux" ^^^^^^^^^^^^^^^^^^ /etc/icinga2/conf.d/hosts_location.conf(144): /etc/icinga2/conf.d/hosts_location.conf(145): }

hobbsh commented 9 years ago

I thought I fixed that... It should be a single = not ==.

You can do a git pull, run the script again, and copy the config over or you can run this command on your config file to get rid of the ==

sed -i 's/vars.os ==/vars.os =/g' /etc/icinga2/conf.d/hosts_location.conf

A side note is that I typically use the -L option to specify a certain network location or datacenter, like DC1 or Headquarters, etc. Maybe I should make it optional?

evanderv commented 9 years ago

Oh ok I really don't need it. I would probably do that later. The -L option that is.

evanderv commented 9 years ago

It looks like they populated and so there was no errors after the restart. Looks good. I'll keep watching if you make changes or additions.

hobbsh commented 9 years ago

Awesome. Just curious - what Linux distro are you running? Running into a few issues on CentOS which is why I ask.

evanderv commented 9 years ago

Ubuntu 14.04

evanderv commented 9 years ago

When the file creates a hosts and ads the object it's grabbing the name of the hosts from the domain servers (Active Directory) but it appends (the ip address) to the host name. Because of this icinga is spitting invalid hostname.

hobbsh commented 9 years ago

I'm not sure how that is happening - can you paste a line of debug output where this is happening to a host?

evanderv commented 9 years ago

Found 1 hosts - gathering more info (can take up to 2 minutes) "hostname" (10.10.10.7) {'sysdesc': '', 'snmp_version': '2c', 'hostname': '', 'vendor': 'NA', 'community': 'unknown'}

hobbsh commented 9 years ago

Hm. Ok - can you provide some details on the host(s)? What kind of devices are these?

Also can you paste the output of 'nmap -v' on your Ubuntu box? Thanks

evanderv commented 9 years ago

Its a windows 2008 server. Starting Nmap 6.40

hobbsh commented 9 years ago

Ok how about the output of:

nmap -sP -sn 10.10.10.7
evanderv commented 9 years ago

Starting Nmap 6.40 ( http://nmap.org ) at 2015-09-02 21:26 EDT Nmap scan report for "hostname" (10.10.10.7) Host is up (0.0017s latency). MAC Address: 00:15:5D:0A:16:05 (Microsoft) Nmap done: 1 IP address (1 host up) scanned in 0.23 seconds

hobbsh commented 9 years ago

Ok I did not account for hostnames being returned by DNS from NMAP scans but should have. I will fix that. Thanks

evanderv commented 9 years ago

np. I am off to bed I can check in the morning. I am in Michigan so I am EST so 1 hour off I think.

hobbsh commented 9 years ago

I'll have it fixed by then. Thanks for reporting your issues, I really appreciate it.

evanderv commented 9 years ago

Glad I can help.

evanderv commented 9 years ago

It worked!

hobbsh commented 9 years ago

Awesome, good to hear. What do you think about its usefulness? Did it make the initial adding hosts easier?

evanderv commented 9 years ago

Yes it did. Works great!

On Thu, Sep 3, 2015 at 12:15 PM, Wylie Hobbs notifications@github.com wrote:

Awesome, good to hear. What do you think about its usefulness? Did it make the initial adding hosts easier?

— Reply to this email directly or view it on GitHub https://github.com/hobbsh/icinga-autod/issues/1#issuecomment-137499511.

hobbsh commented 9 years ago

Great to hear! I'm gonna close this issue out but if you have any questions, issues or suggestions please let me know. Thanks again,

Wylie