Skip to content

Commit

Permalink
enh(engine/gRPC): GetHost function return all about host
Browse files Browse the repository at this point in the history
  • Loading branch information
sechkem committed Sep 25, 2024
1 parent 6ff1486 commit bff7ca5
Show file tree
Hide file tree
Showing 5 changed files with 383 additions and 46 deletions.
10 changes: 7 additions & 3 deletions ccc/client.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2022 Centreon
* Copyright 2024 Centreon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,10 +36,13 @@ using namespace com::centreon::ccc;
* @param channel The channel to use to the gRPC server.
* @param color_enabled A boolean telling if we should use colors or not.
*/
client::client(std::shared_ptr<grpc::Channel> channel, bool color_enabled)
client::client(std::shared_ptr<grpc::Channel> channel,
bool color_enabled,
bool always_print_primitive_fields)
: _stub{std::make_unique<grpc::GenericStub>(channel)},
_server{CCC_NONE},
_color_enabled{color_enabled} {
_color_enabled{color_enabled},
_always_print_primitive_fields{always_print_primitive_fields} {
const ::google::protobuf::Empty e;
com::centreon::broker::Version broker_v;
com::centreon::engine::Version engine_v;
Expand Down Expand Up @@ -210,6 +213,7 @@ std::string client::call(const std::string& cmd, const std::string& args) {
std::string retval;
google::protobuf::util::JsonPrintOptions json_options;
json_options.add_whitespace = true;
json_options.always_print_primitive_fields = _always_print_primitive_fields;
auto status = google::protobuf::util::MessageToJsonString(
*output_message, &retval, json_options);

Expand Down
7 changes: 5 additions & 2 deletions ccc/client.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** Copyright 2022 Centreon
** Copyright 2024 Centreon
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,10 +48,13 @@ class client {
std::unique_ptr<grpc::GenericStub> _stub;
type _server;
bool _color_enabled;
bool _always_print_primitive_fields;
grpc::CompletionQueue _cq;

public:
client(std::shared_ptr<grpc::Channel> channel, bool color_enabled = true);
client(std::shared_ptr<grpc::Channel> channel,
bool color_enabled = true,
bool _always_print_primitive_fields = false);
std::list<std::string> methods() const;
std::string call(const std::string& cmd, const std::string& args);
std::string info_method(const std::string& cmd) const;
Expand Down
53 changes: 31 additions & 22 deletions ccc/main.cc
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
* Copyright 2022 Centreon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : [email protected]
*/
* Copyright 2024 Centreon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : [email protected]
*/

#include <absl/strings/ascii.h>
#include <absl/strings/numbers.h>
Expand All @@ -31,10 +31,13 @@
using namespace nlohmann;
using namespace com::centreon::ccc;

static struct option long_options[] = {
{"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'},
{"port", required_argument, 0, 'p'}, {"list", no_argument, 0, 'l'},
{"nocolor", no_argument, 0, 'n'}, {0, 0, 0, 0}};
static struct option long_options[] = {{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{"port", required_argument, 0, 'p'},
{"list", no_argument, 0, 'l'},
{"nocolor", no_argument, 0, 'n'},
{"full", no_argument, 0, 'F'},
{0, 0, 0, 0}};

static void usage(bool color_enabled) {
std::cout << color<color_method>(color_enabled)
Expand All @@ -56,6 +59,8 @@ static void usage(bool color_enabled) {
" Displays the available methods.\n"
" -n, --nocolor\n"
" Outputs are displayed with the current color.\n"
" -F, --full\n"
" Force fields with default values to always print.\n"
"\n"
<< color<color_method>(color_enabled)
<< "Examples:" << color<color_reset>(color_enabled)
Expand All @@ -73,8 +78,9 @@ int main(int argc, char** argv) {
bool list = false;
bool help = false;
bool color_enabled = true;
bool always_print_primitive_fields = false;

while ((opt = getopt_long(argc, argv, "vhnp:l", long_options,
while ((opt = getopt_long(argc, argv, "vhnp:lF", long_options,
&option_index)) != -1) {
switch (opt) {
case 'v':
Expand All @@ -97,6 +103,9 @@ int main(int argc, char** argv) {
case 'l':
list = true;
break;
case 'F':
always_print_primitive_fields = true;
break;
default:
std::cerr << "Unrecognized argument '" << opt << "'" << std::endl;
exit(3);
Expand All @@ -118,7 +127,7 @@ int main(int argc, char** argv) {
grpc::CreateChannel(url, grpc::InsecureChannelCredentials());

try {
client clt(channel, color_enabled);
client clt(channel, color_enabled, always_print_primitive_fields);
if (help) {
std::string message{clt.info_method(argv[optind])};
std::cout << "Input message for this function:\n" << message << std::endl;
Expand Down
116 changes: 116 additions & 0 deletions engine/enginerpc/engine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,122 @@ message EngineHost {
UNREACHABLE = 2;
}
State current_state = 6;
string display_name = 7;
string parent_hosts = 8;
string child_hosts = 9;
string services = 10;
string check_command = 11;
State initial_state = 12;
uint32 check_interval = 13;
double retry_interval = 14;
int32 max_attempts = 15;
string event_handler = 16;
string contact_groups = 17;
string contacts = 18;
uint32 notification_interval = 19;
uint32 first_notification_delay = 20;
uint32 recovery_notification_delay = 21;
bool notify_up = 22;
bool notify_down = 23;
bool notify_unreachable = 24;
bool notify_on_flappingstart = 25;
bool notify_on_flappingstop = 26;
bool notify_on_flappingdisabled = 27;
bool notify_downtime = 28;
string notification_period = 29;
bool flap_detection_enabled = 30;
double low_flap_threshold = 31;
double high_flap_threshold = 32;
bool flap_detection_on_up = 33;
bool flap_detection_on_down = 34;
bool flap_detection_on_unreachable = 35;
bool stalk_on_up = 36;
bool stalk_on_down = 37;
bool stalk_on_unreachable = 38;
bool check_freshness = 39;
int32 freshness_threshold = 40;
bool process_performance_data = 41;
bool checks_enabled = 42;
bool accept_passive_checks = 43;
bool event_handler_enabled = 44;
int32 retain_status_information = 45;
bool retain_nonstatus_information = 46;
bool obsess_over_host = 47;
string notes = 48;
string notes_url = 49;
string action_url = 50;
string icon_image = 51;
string icon_image_alt = 52;
string vrml_image = 53;
string statusmap_image = 54;
bool have_2d_coords = 55;
double x_2d = 56;
double y_2d = 57;
bool have_3d_coords = 58;
double x_3d = 59;
double y_3d = 60;
double z_3d = 61;
int32 should_be_drawn = 62;
enum AckType {
NONE = 0;
NORMAL = 1;
STICKY = 2;
}
AckType acknowledgement = 63;
enum CheckType {
CHECK_ACTIVE = 0;
CHECK_PASSIVE = 1;
}
CheckType check_type = 64;
State last_state = 65;
State last_hard_state = 66;
string plugin_output = 67;
string long_plugin_output = 68;
string perf_data = 69;
State state_type = 70;
int32 current_attempt = 71;
uint64 current_event_id = 72;
uint64 last_event_id = 73;
uint64 current_problem_id = 74;
uint64 last_problem_id = 75;
double latency = 76;
double execution_time = 77;
bool is_executing = 78;
int32 check_options = 79;
bool notifications_enabled = 80;
string last_notification = 81;
string next_notification = 82;
string next_check = 83;
bool should_be_scheduled = 84;
string last_check = 85;
string last_state_change = 86;
string last_hard_state_change = 87;
string last_time_up = 88;
string last_time_down = 89;
string last_time_unreachable = 90;
bool has_been_checked = 91;
bool is_being_freshened = 92;
bool notified_on_down = 93;
bool notified_on_unreachable = 94;
bool no_more_notifications = 95;
uint64 current_notification_id = 96;
int32 scheduled_downtime_depth = 97;
int32 pending_flex_downtime = 98;
string state_history = 99;
uint32 state_history_index = 100;
string last_state_history_update = 101;
bool is_flapping = 102;
uint64 flapping_comment_id = 103;
double percent_state_change = 104;
int32 total_services = 105;
uint64 total_service_check_interval = 106;
uint32 modified_attributes = 107;
int32 circular_path_checked = 108;
bool contains_circular_path = 109;
string timezone = 110;
uint64 icon_id = 111;
string group_name = 112;
repeated string custom_variables = 113;
}

message ContactIdentifier {
Expand Down
Loading

0 comments on commit bff7ca5

Please sign in to comment.