Icinga / icinga2

The core of our monitoring platform with a powerful configuration language and REST API.
https://icinga.com/docs/icinga2/latest
GNU General Public License v2.0
1.99k stars 573 forks source link

Icinga2 and Icingacli should return nonzero status code on invalid parameters #6585

Open MVKozlov opened 6 years ago

MVKozlov commented 6 years ago

icinga2 sdfsdfsdf; echo "Status Code:$?"

icingacli sdfsdfsdf; echo "Status Code:$?"

Expected Behavior

both commands should return non-zeno status code

Current Behavior

Status Code:0

Context

It is good for automation and helps mitigate typing errors

dnsmichi commented 6 years ago

Can you look into the code and create PR please? :)

mcktr commented 6 years ago

Keep in mind that icingacli is part of Icinga/icingaweb2, so a PR is welcome there as well :)

MVKozlov commented 6 years ago

Sorry, my c++ knowlege does not allow this. And my php knowlege also too small, but for Icingacli I can suppose that this will be enought

--- library/Icinga/Application/Cli.php.orig        2018-09-05 10:21:19.597856863 +0300
+++ library/Icinga/Application/Cli.php     2018-09-05 10:20:26.109856269 +0300
@@ -146,11 +146,12 @@
     {
         $loader = $this->cliLoader();
         $loader->parseParams();
-        $loader->dispatch();
+        $result = $loader->dispatch();
         Benchmark::measure('All done');
         if ($this->showBenchmark) {
             Benchmark::dump();
         }
+       if ($result === FALSE) exit(1);
     }

     protected function dispatchEndless()

I think this change too small for PR :)

dnsmichi commented 6 years ago

Please create a PR over at icinga/icingaweb2 for review. Even if it would contain a typo fix, it is very easy to review and merge, it saves time.

dnsmichi commented 5 years ago

Needed something simple before digging into the hard issues for 2.11 again.

dnsmichi commented 5 years ago

Unfortunately not fixed, this breaks our sub commands.