TypeError: 'NoneType' object has no attribute '__getitem__'

117 views
Skip to first unread message

mortis

unread,
Jun 20, 2013, 5:15:18 AM6/20/13
to pynag-...@googlegroups.com
Hi there!

I'm checking out this very promising pynag-tool and it works very well with basic configuration.
However, I'm running into some trouble when trying to use it to parse the config we have at work.

I'm not really sure how to start debugging this to find out where it actually crashes, but here's what I get:


python pynag-test.py "Ping" breeze
Traceback (most recent call last):
  File "pynag-test.py", line 19, in <module>
    nc.parse()
  File "/usr/local/lib/python2.7/dist-packages/pynag/Parsers/__init__.py", line 1144, in parse
    self._load_file(cfg_file)
  File "/usr/local/lib/python2.7/dist-packages/pynag/Parsers/__init__.py", line 248, in _load_file
    current['meta']['line_end'] = line_num
TypeError: 'NoneType' object has no attribute '__getitem__'


I'm running nagios 3.4.1-2 on Ubuntu 12.10. (for testing on my desktop)

mortis

Páll Sigurðsson

unread,
Jun 20, 2013, 5:40:19 AM6/20/13
to pynag-...@googlegroups.com
Hi Morten,

Does nagios accept your configuration, i.e. if you run:

nagios -v /etc/nagios/nagios.cfg | grep -i error




mortis

--
You received this message because you are subscribed to the Google Groups "pynag-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pynag-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Morten Bekkelund

unread,
Jun 20, 2013, 5:49:51 AM6/20/13
to pynag-...@googlegroups.com
Hi Páll,

Yes, it does. It has warnings, but no errors.

Páll Sigurðsson

unread,
Jun 20, 2013, 5:56:17 AM6/20/13
to pynag-...@googlegroups.com
Can you comment out line 248 in file:

/usr/local/lib/python2.7/dist-packages/pynag/Parsers/__init__.py"

It should read something like this: 

current['meta']['line_end'] = line_num
There is some error handling code after that, so if there is a problem with the config, maybe you get a better error message now.

Morten Bekkelund

unread,
Jun 20, 2013, 6:13:42 AM6/20/13
to pynag-...@googlegroups.com
Hmmmm nice, that actually pointed me to an error in a file!
pynag.Parsers.ParserError: "Encountered Unexpected end of object definition in file 'someconfigfile.cfg'."

This is weird, cause nagios accepts it, but now, atleast, i know where to look!
Thanks a lot!



--

Páll Sigurðsson

unread,
Jun 20, 2013, 6:38:19 AM6/20/13
to pynag-...@googlegroups.com
Yup, looks like you have a "}" before a "define ... {" in that file.

Remember to browse through the examples at http://pynag.org/ to get a feeling on how to parse.

the pynag.Parsers module is very low level, and there is a more "pythonic" one out there called pynag.Model 
Reply all
Reply to author
Forward
0 new messages