Problems with a .php Check

Hello Everybody,

i`ve got a Problem with a Check.
The Check is written in php and if i run the Check on the CLI than i have a few Errors.
e.g.

root@WS-iCinga2:/lib/nagios/plugins# ./check_apc_usv.php
: Datei oder Verzeichnis nicht gefunden
./check_apc_usv.php: Zeile 2: =: Befehl nicht gefunden
./check_apc_usv.php: Zeile 2: $’\r’: Befehl nicht gefunden
./check_apc_usv.php: Zeile 3: =: Befehl nicht gefunden
./check_apc_usv.php: Zeile 3: $’\r’: Befehl nicht gefunden
./check_apc_usv.php: Zeile 4: $’\r’: Befehl nicht gefunden
./check_apc_usv.php: Zeile 5: =: Befehl nicht gefunden
./check_apc_usv.php: Zeile 5: $’\r’: Befehl nicht gefunden
./check_apc_usv.php: Zeile 6: =: Befehl nicht gefunden
./check_apc_usv.php: Zeile 6: $’\r’: Befehl nicht gefunden
./check_apc_usv.php: Zeile 7: $’\r’: Befehl nicht gefunden
./check_apc_usv.php: Zeile 8: =: Befehl nicht gefunden
./check_apc_usv.php: Zeile 8: $’\r’: Befehl nicht gefunden
./check_apc_usv.php: Zeile 9: $’\r’: Befehl nicht gefunden
./check_apc_usv.php: Zeile 10: Syntaxfehler beim unerwarteten Wort »(«
'/check_apc_usv.php: Zeile 10: `$upsBasicOutputStatus = @snmpget($host, $community, “.1.3.6.1.4.1.318.1.1.1.4.1.1.0”);

How i Can fix this? Do in need a interpreter?

Thank you!
Platform version: Ubuntu 20.04.3 LTS
Compiler: GNU 9.3.0
Kernel version: 5.13.0-27-generic
iCinga version: r2.13.2-1
Enabled features: api checker command graphite ido-mysql influxdb mainlog notification

  1. Did you write the script yourself or get it from somewhere else (if so,
    where)?

  2. What are the first 5 non-blank lines of the script?

  3. Have you checked that the script is not in MS-Dos format with ^M characters
    at the end of each line?

I’m betting that the #!/ line at the start of the script points to a non-
existent interpreter because it ends in ^M and no file exists with that name.

Antony.

Good Morning Antony,

thanks for your Answer.
No, i found the Script by a Google Search.
The name ist check-apc-usv from exchange.icinga.com
But i`ve got Problems with any .php Check.

Okay, so I found check-apc-usv :: Icinga Exchange and I
downloaded it.

I’m intrigued that the project was created on 2020-06-26 and the latest
release is 2019-12-17

Anyway, the first line of the script is:

<?php That means it has to be processed directly by a PHP interpreter; it cannot be run as a shell script. Therefore it's not clear to me how this should be used as an Icinga plugin. I notice that https://exchange.icinga.com/V4n1X/check-apc-usv/comments has only a single comment / question, which is "Hello, can you explain me how i can add install this check?" It's a pity the author has not answered. As a general guide, if a script does not have a first line starting with "#!/" (common examples are "#!/bin/bash" and "#!/usr/bin/perl") then it cannot be used directly as an Icinga check plugin, because without that line, Icinga has no idea how to run the code contained in the script. My recommendation is to find an alternative USV/UPS check script, or to contact the author of this one and find out how it was intended to be used with Icinga or Nagios. Regards, Antony.

that means the script should be executed by a php interpreter
and yess you need to have php installed!

so the icinga command will be /realpathto/php with a first parameter path of the script.

but there is a better approach
look into [https://exchange.nagios.org/directory/Plugins/Websites%2C-Forms-and-Transactions/check_curl2/details]

you will see that the script starts with:

#!/usr/bin/php -q

which is want you can add to your script so the unix shell knows how to execute your script.
don’t forget to set the permission of the script to executable

chmod +x
after that your command can be the path of the script as you are using it now
best regards nicolas

Thank you!
I`ve go add at the first Line #!/usr/bin/php -q
And now it Works, thank you very much.

1 Like

Hello Mueke666,
I want to use that script in my environment also.
But I don’t know how to install it on my icinga2web server. At the moment I only use the preinstalled scripts/checks and .pl-scripts to check health.
Would you like to give me a little onboarding support?

Thank you in advance.

Sebastian