]> granicus.if.org Git - icinga2/blobdiff - plugins/check_nscp_api.cpp
Merge pull request #6882 from Icinga/bugfix/influxdb-gaps-6841
[icinga2] / plugins / check_nscp_api.cpp
index 333b217ab7531ad6745f58e00e9fd57af4bf1689..f48c63ab88c7f856bf8799aadc2a5947d85d33b0 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * Icinga 2                                                                   *
- * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)  *
+ * Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/)      *
  *                                                                            *
  * This program is free software; you can redistribute it and/or              *
  * modify it under the terms of the GNU General Public License                *
@@ -25,6 +25,7 @@
 #include "base/application.hpp"
 #include "base/json.hpp"
 #include "base/string.hpp"
+#include "base/logger.hpp"
 #include "base/exception.hpp"
 #include <boost/program_options.hpp>
 #include <boost/algorithm/string/split.hpp>
@@ -93,8 +94,10 @@ static Dictionary::Ptr QueryEndpoint(const String& host, const String& port, con
                req->RequestUrl->SetArrayFormatUseBrackets(false);
 
                req->AddHeader("password", password);
-               if (l_Debug)
-                       std::cout << "Sending request to 'https://" << host << ":" << port << req->RequestUrl->Format(false, false) << "'\n";
+               if (l_Debug) {
+                       std::cout << "Sending request to 'https://" << host << ":" << port << req->RequestUrl->Format(false, false) << "'\n"
+                               << "Headers: " << JsonEncode(req->Headers) << "\n";
+               }
 
                // Submits the request. The 'ResultHttpCompletionCallback' is called once the HttpRequest receives an answer,
                // which then sets 'ready' to true
@@ -223,7 +226,7 @@ static int FormatOutput(const Dictionary::Ptr& result)
                state == "UNKNOWN" ? 3 : 4;
 
        if (creturn == 4) {
-               std::cout << "check_nscp UNKNOWN Answer format error: 'result' was not a known state.\n";
+               std::cout << "check_nscp_api UNKNOWN Answer format error: 'result' was not a known state.\n";
                return 3;
        }
 
@@ -282,6 +285,12 @@ int main(int argc, char **argv)
 
        l_Debug = vm.count("debug") > 0;
 
+       // Initialize logger
+       if (l_Debug)
+               Logger::SetConsoleLogSeverity(LogDebug);
+       else
+               Logger::SetConsoleLogSeverity(LogWarning);
+
        // Create the URL string and escape certain characters since Url() follows RFC 3986
        String endpoint = "/query/" + vm["query"].as<std::string>();
        if (!vm.count("arguments"))