mirror of
https://github.com/Icinga/icinga2.git
synced 2026-02-19 02:29:16 -05:00
I've used the following command to replace the original copyright header
lines in a C-style comment block:
```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{/\*[^*]*\(\s*c\s*\)\s*(\d{4})\s*Icinga\s+GmbH[^*]*\*/}{// SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n// SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```
For files that use shell-style comments (#) like CMakeLists.txt, I've
used this command:
```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{#.*\(\s*c\s*\)\s(\d{4})\sIcinga\s+GmbH.*}{# SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n# SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```
And for SQL files:
```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{--.*\(c\)\s(\d{4})\sIcinga\sGmbH.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{-- Copyright \(c\)\s(\d{4})\sIcinga\s+Development\sTeam.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```
108 lines
3 KiB
C++
108 lines
3 KiB
C++
// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "livestatus/livestatusquery.hpp"
|
|
#include "base/application.hpp"
|
|
#include "base/stdiostream.hpp"
|
|
#include "base/json.hpp"
|
|
#include <BoostTestTargetConfig.h>
|
|
|
|
using namespace icinga;
|
|
|
|
String LivestatusQueryHelper(const std::vector<String>& lines)
|
|
{
|
|
LivestatusQuery::Ptr query = new LivestatusQuery(lines, "");
|
|
|
|
std::stringstream stream;
|
|
StdioStream::Ptr sstream = new StdioStream(&stream, false);
|
|
|
|
query->Execute(new StoppableWaitGroup(), sstream);
|
|
|
|
String output;
|
|
String result;
|
|
|
|
StreamReadContext src;
|
|
for (;;) {
|
|
StreamReadStatus srs = sstream->ReadLine(&result, src);
|
|
|
|
if (srs == StatusEof)
|
|
break;
|
|
|
|
if (srs != StatusNewItem)
|
|
continue;
|
|
|
|
if (result.GetLength() > 0)
|
|
output += result + "\n";
|
|
else
|
|
break;
|
|
}
|
|
|
|
BOOST_TEST_MESSAGE("Query Result: " + output);
|
|
|
|
return output;
|
|
}
|
|
|
|
//____________________________________________________________________________//
|
|
|
|
BOOST_AUTO_TEST_SUITE(livestatus)
|
|
|
|
BOOST_AUTO_TEST_CASE(hosts)
|
|
{
|
|
BOOST_TEST_MESSAGE( "Querying Livestatus...");
|
|
|
|
std::vector<String> lines;
|
|
lines.emplace_back("GET hosts");
|
|
lines.emplace_back("Columns: host_name address check_command");
|
|
lines.emplace_back("OutputFormat: json");
|
|
lines.emplace_back("\n");
|
|
|
|
/* use our query helper */
|
|
String output = LivestatusQueryHelper(lines);
|
|
|
|
Array::Ptr query_result = JsonDecode(output);
|
|
|
|
/* the outer elements */
|
|
BOOST_CHECK(query_result->GetLength() > 1);
|
|
|
|
Array::Ptr res1 = query_result->Get(0);
|
|
Array::Ptr res2 = query_result->Get(1);
|
|
|
|
/* results are non-deterministic and not sorted by livestatus */
|
|
BOOST_CHECK(res1->Contains("test-01") || res2->Contains("test-01"));
|
|
BOOST_CHECK(res1->Contains("test-02") || res2->Contains("test-02"));
|
|
BOOST_CHECK(res1->Contains("127.0.0.1") || res2->Contains("127.0.0.1"));
|
|
BOOST_CHECK(res1->Contains("127.0.0.2") || res2->Contains("127.0.0.2"));
|
|
|
|
BOOST_TEST_MESSAGE("Done with testing livestatus hosts...");
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(services)
|
|
{
|
|
BOOST_TEST_MESSAGE( "Querying Livestatus...");
|
|
|
|
std::vector<String> lines;
|
|
lines.emplace_back("GET services");
|
|
lines.emplace_back("Columns: host_name service_description check_command notes");
|
|
lines.emplace_back("OutputFormat: json");
|
|
lines.emplace_back("\n");
|
|
|
|
/* use our query helper */
|
|
String output = LivestatusQueryHelper(lines);
|
|
|
|
Array::Ptr query_result = JsonDecode(output);
|
|
|
|
/* the outer elements */
|
|
BOOST_CHECK(query_result->GetLength() > 1);
|
|
|
|
Array::Ptr res1 = query_result->Get(0);
|
|
Array::Ptr res2 = query_result->Get(1);
|
|
|
|
/* results are non-deterministic and not sorted by livestatus */
|
|
BOOST_CHECK(res1->Contains("livestatus") || res2->Contains("livestatus")); //service_description
|
|
BOOST_CHECK(res1->Contains("test livestatus") || res2->Contains("test livestatus")); //notes
|
|
|
|
BOOST_TEST_MESSAGE("Done with testing livestatus services...");
|
|
}
|
|
//____________________________________________________________________________//
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|