Nagios Core, fresh build. (expecting ")")

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
jAjXFS8
Posts: 5
Joined: Mon Feb 22, 2021 3:11 pm

Nagios Core, fresh build. (expecting ")")

Post by jAjXFS8 »

Nagios Core, fresh build. Using multiple editions of the /usr/local/nagios/plugins/check_ncpa.py -H plugin I am getting an error:

./check_ncpa.py: 1: Syntax error: word unexpected (expecting ")")

I have downloaded this from the main page: https://www.nagios.org/ncpa/ (AKA https://assets.nagios.com/downloads/ncp ... cpa.tar.gz ) as well as from sourceforge. As this same message appears when testing the plugin from command line and in the Nagios Core GUI it seems like there is a missing ')' in the source code, however I would be surprised if I' the first to see this as this version appears to have been out for over a week. (Not seeing any related posts though.) I am newish to Nagios and could be missing something basic. Thank you for any guidance and direction.

Thought I had downloaded 1.2.3 somewhere a while back but can't find it now either locally or to download. Thanks!
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Nagios Core, fresh build. (expecting ")")

Post by gormank »

Here are some possibilities. I think we'd need more specific info on the plugin/command that's giving the error to understand the issue better.

https://www.google.com/search?q=check_n ... ng+%22)%22)&rlz=1C1GCEJ_enUS870US870&oq=check_ncpa.py%3A+1%3A+Syntax+error%3A+word+unexpected+(expecting+%22)%22)&aqs=chrome..69i57.489j0j15&sourceid=chrome&ie=UTF-8
jAjXFS8
Posts: 5
Joined: Mon Feb 22, 2021 3:11 pm

Re: Nagios Core, fresh build. (expecting ")")

Post by jAjXFS8 »

Sorry for delay in reply, didn't set up notification settings Rookie mistake. Thank you for the prompt post allow and the reply. So I get this error in Nagios UI itself regardless of the actual test (Just using the basic defaults at this point): (No output on stdout) stderr: /usr/local/nagios/libexec/check_ncpa.py: 1: Syntax error: word unexpected (expecting ")")
The thing that I find most interesting is that attempting to run the command in the shell directly ( I.E. sudo ./check_ncpa.py -H
) get's the exact same message: So I don't think it's the Nagios integration or plugin runtime, it's something in the script itself (which seems unlikely) or my python interpreter?

I did try a lot of searches before posting as thought it would be surprising if this was just me. So far I have still not found anything to guide me to what I am seeing even when using the search string provided.
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Nagios Core, fresh build. (expecting ")")

Post by gormank »

A few guesses and things to check...
Try running the script with python:

python check_ncpa.py

which python
yum list python
locate python

Maybe there are multiple python executables installed. If so, maybe try running the check script with different versions using the path to the the binary.

If you find one that works, replace the shebang line in the script with the one that works

Change
#!/usr/bin/env python
to
#!/path/to/good/python
jAjXFS8
Posts: 5
Joined: Mon Feb 22, 2021 3:11 pm

Re: Nagios Core, fresh build. (expecting ")")

Post by jAjXFS8 »

Thank you for the additional follow-up, sooo, I'm thinking you are right that somewhere in here is the crux of the issue. After going through the process outlined in https://support.nagios.com/kb/article/n ... tml#Ubuntu on a fresh Ubuntu install I do not have python installed, but I do have python3. Even when attempting to run the NCPA script with Python 3 I get an error, but not quite the same:

/usr/local/nagios/libexec$ sudo python3 check_ncpa.py -H
File "check_ncpa.py", line 1
SyntaxError: Non-UTF-8 code starting with '\x8b' in file check_ncpa.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Back to the original question, is there a download location for a prior version of the NCPA plugin? It really looks like there is an issue with this version's creation. AKA https://assets.nagios.com/downloads/ncp ... cpa.tar.gz is currently 1.2.4 per the site, does anyone have a 1.2.3 or another recnt-ish one to test with?
?
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Nagios Core, fresh build. (expecting ")")

Post by gormank »

Hmm, maybe try checking to see if it has DOS/Windows CRLFs?

file check_ncpa.py
dos2unix check_ncpa.py
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Nagios Core, fresh build. (expecting ")")

Post by gormank »

If you don't have a python binary named python, the script will be interpreted by bash and you should expect a syntax error. As far as encoding goes with python3, I'd look at the file and see if it has screwy characters in it. You might run it through strings to weed out any funny invisible stuff as well, or download it from github.

I downloaded it and ran it w/o errors. My python is 2.7.5 and a which on the absolute path says it's a link to python2. I'll guess that's your issue...

$ sudo yum list python
Loaded plugins: enabled_repos_upload, package_upload, product-id, search-disabled-repos, subscription-manager, tracer_upload
Installed Packages
python.x86_64 2.7.5-87.el7_7 @rhel-7-server-eus-rpms
Uploading Enabled Repositories Report
Loaded plugins: product-id, subscription-manager
$ which python
/usr/bin/python
$ file /usr/bin/python
/usr/bin/python: symbolic link to `python2'
$ file ./check_ncpa.py
./check_ncpa.py: Python script, ASCII text executable
jAjXFS8
Posts: 5
Joined: Mon Feb 22, 2021 3:11 pm

Re: Nagios Core, fresh build. (expecting ")")

Post by jAjXFS8 »

To summarize the error I had [(expecting ")")] appears to be a malformed download, the other issue confounding the investigation was no redirect (ln) for usr/bin/python

Thank you gormank. On the third wget and tar on the plugin itself I am no longer getting that error when running the plugin with python within the cli directly. I then linked the expected folder as seen here. sudo ln /usr/bin/python3 /usr/bin/python. That part made it so that in the CLI I can run ./check_ncpa.py -h directly without calling python as expected. I did also download python2 as suggested and it works that way too but at least -h runs either way. Nagios is at least attempting to connect with my client now and I hope I can work out the issues from there as what I am seeing now is I think unrelated to the above. Thank you for helping me get my brain turned the correct direction.
jAjXFS8
Posts: 5
Joined: Mon Feb 22, 2021 3:11 pm

Re: Nagios Core, fresh build. (expecting ")")

Post by jAjXFS8 »

Yep, looks good now and got through the client agent issues and it's working. I believe this thread can be closed when time allows. (I'm not seeing a way to close it myself.)

Thank you for your time and attention, it was very helpful.
Locked