Skip to content

Commit

Permalink
enh(severity): we can add a severity to a service.
Browse files Browse the repository at this point in the history
REFS: MON-12278
  • Loading branch information
bouda1 committed Apr 21, 2022
1 parent 1c04f51 commit 4bdd805
Show file tree
Hide file tree
Showing 33 changed files with 1,195 additions and 692 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ broker/script/cbd.init
broker/script/watchdog.json
doc/_build
doc/devel-doc
broker/doc/devel-doc
engine/doc/devel-doc
engine_pb2.py
engine_pb2.pyc
engine_pb2_grpc.py
Expand Down
7 changes: 6 additions & 1 deletion bbdo/severity.proto
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@ message Severity {
uint32 level = 3;
uint64 icon_id = 4;
string name = 5;
uint64 poller_id = 6;
enum Type {
SERVICE = 0;
HOST = 1;
}
Type type = 6;
uint64 poller_id = 7;
}
38 changes: 23 additions & 15 deletions broker/neb/src/callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,7 @@ int neb::callback_pb_host(int callback_type, void* data) {
host.set_statusmap_image(
misc::string::check_string_utf8(eh->get_statusmap_image()));
host.set_timezone(eh->get_timezone());
host.set_severity_id(eh->get_severity() ? eh->get_severity()->id() : 0);

// Find host ID.
uint64_t host_id = engine::get_host_id(host.host_name());
Expand Down Expand Up @@ -2296,39 +2297,41 @@ int neb::callback_pb_service(int callback_type, void* data) {
static_cast<nebstruct_adaptive_service_data*>(data);
const engine::service* es{static_cast<engine::service*>(ds->object_ptr)};

if (ds->type == NEBTYPE_ADAPTIVESERVICE_UPDATE && ds->attr != MODATTR_ALL) {
log_v2::neb()->trace("modified_attribute = {}", ds->modified_attribute);
if (ds->type == NEBTYPE_ADAPTIVESERVICE_UPDATE &&
ds->modified_attribute != MODATTR_ALL) {
auto s{std::make_shared<neb::pb_adaptive_service>()};
AdaptiveService& srv = s.get()->mut_obj();
if (ds->attr & MODATTR_NOTIFICATIONS_ENABLED)
if (ds->modified_attribute & MODATTR_NOTIFICATIONS_ENABLED)
srv.set_notifications_enabled(es->get_notifications_enabled());
else if (ds->attr & MODATTR_ACTIVE_CHECKS_ENABLED) {
else if (ds->modified_attribute & MODATTR_ACTIVE_CHECKS_ENABLED) {
srv.set_active_checks_enabled(es->active_checks_enabled());
srv.set_should_be_scheduled(es->get_should_be_scheduled());
} else if (ds->attr & MODATTR_PASSIVE_CHECKS_ENABLED)
} else if (ds->modified_attribute & MODATTR_PASSIVE_CHECKS_ENABLED)
srv.set_passive_checks_enabled(es->passive_checks_enabled());
else if (ds->attr & MODATTR_EVENT_HANDLER_ENABLED)
else if (ds->modified_attribute & MODATTR_EVENT_HANDLER_ENABLED)
srv.set_event_handler_enabled(es->event_handler_enabled());
else if (ds->attr & MODATTR_FLAP_DETECTION_ENABLED)
else if (ds->modified_attribute & MODATTR_FLAP_DETECTION_ENABLED)
srv.set_flap_detection_enabled(es->flap_detection_enabled());
else if (ds->attr & MODATTR_OBSESSIVE_HANDLER_ENABLED)
else if (ds->modified_attribute & MODATTR_OBSESSIVE_HANDLER_ENABLED)
srv.set_obsess_over(es->obsess_over());
else if (ds->attr & MODATTR_EVENT_HANDLER_COMMAND)
else if (ds->modified_attribute & MODATTR_EVENT_HANDLER_COMMAND)
srv.set_event_handler(
misc::string::check_string_utf8(es->event_handler()));
else if (ds->attr & MODATTR_CHECK_COMMAND)
else if (ds->modified_attribute & MODATTR_CHECK_COMMAND)
srv.set_check_command(
misc::string::check_string_utf8(es->check_command()));
else if (ds->attr & MODATTR_NORMAL_CHECK_INTERVAL)
else if (ds->modified_attribute & MODATTR_NORMAL_CHECK_INTERVAL)
srv.set_check_interval(es->check_interval());
else if (ds->attr & MODATTR_RETRY_CHECK_INTERVAL)
else if (ds->modified_attribute & MODATTR_RETRY_CHECK_INTERVAL)
srv.set_retry_interval(es->retry_interval());
else if (ds->attr & MODATTR_MAX_CHECK_ATTEMPTS)
else if (ds->modified_attribute & MODATTR_MAX_CHECK_ATTEMPTS)
srv.set_max_check_attempts(es->max_check_attempts());
else if (ds->attr & MODATTR_FRESHNESS_CHECKS_ENABLED)
else if (ds->modified_attribute & MODATTR_FRESHNESS_CHECKS_ENABLED)
srv.set_check_freshness(es->check_freshness_enabled());
else if (ds->attr & MODATTR_CHECK_TIMEPERIOD)
else if (ds->modified_attribute & MODATTR_CHECK_TIMEPERIOD)
srv.set_check_period(es->check_period());
else if (ds->attr & MODATTR_NOTIFICATION_TIMEPERIOD)
else if (ds->modified_attribute & MODATTR_NOTIFICATION_TIMEPERIOD)
srv.set_notification_period(es->notification_period());
else {
log_v2::neb()->error("callbacks: adaptive service not implemented.");
Expand Down Expand Up @@ -2477,13 +2480,17 @@ int neb::callback_pb_service(int callback_type, void* data) {
srv.set_state_type(static_cast<Service_StateType>(
es->has_been_checked() ? es->get_state_type()
: engine::notifier::hard));
srv.set_severity_id(es->get_severity() ? es->get_severity()->id() : 0);

// Search host ID and service ID.
std::pair<uint64_t, uint64_t> p;
p = engine::get_host_and_service_id(es->get_hostname(),
es->get_description());
srv.set_host_id(p.first);
srv.set_service_id(p.second);
if (srv.host_id() && srv.service_id())
log_v2::neb()->debug("callbacks: service ({}, {}) has a severity id {}",
srv.host_id(), srv.service_id(), srv.severity_id());
if (srv.host_id() && srv.service_id()) {
// Send service event.
log_v2::neb()->info("callbacks: new service {} ('{}') on host {}",
Expand Down Expand Up @@ -2607,6 +2614,7 @@ int32_t neb::callback_severity(int callback_type __attribute__((unused)),
sv.set_level(es->level());
sv.set_icon_id(es->icon_id());
sv.set_name(es->name());
sv.set_type(static_cast<com::centreon::broker::Severity_Type>(es->type()));

// Send event(s).
gl_publisher.write(s);
Expand Down
1 change: 1 addition & 0 deletions broker/neb/src/initial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ void neb::send_initial_configuration() {
* Send initial configuration to the global publisher.
*/
void neb::send_initial_pb_configuration() {
send_severity_list();
send_pb_host_list();
send_pb_service_list();
send_custom_variables_list();
Expand Down
92 changes: 53 additions & 39 deletions broker/simu/docker/centreon_storage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2280,64 +2280,78 @@ CREATE TABLE `servicestateevents` (
--
-- Table structure for table `severities`
--
CREATE TABLE severities (
`id` bigint unsigned NOT NULL,
`name` varchar(255) DEFAULT NULL,
CREATE TABLE `severities` (
`severity_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`id` bigint(20) unsigned NOT NULL,
`type` tinyint(4) unsigned NOT NULL COMMENT '0=service, 1=host',
`name` varchar(255) NOT NULL,
`level` int(11) unsigned NOT NULL,
`icon_id` bigint unsigned default NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

`icon_id` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`severity_id`),
UNIQUE KEY `severities_id_type_uindex` (`id`,`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


--
-- Table structure for table `tags`
--
CREATE TABLE tags (
`id` bigint unsigned NOT NULL,
`name` varchar(255) DEFAULT NULL,
`type` int(11) unsigned NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `tags` (
`tag_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`id` bigint(20) unsigned NOT NULL,
`type` tinyint(3) unsigned NOT NULL COMMENT '0=servicegroup, 1=hostgroup, 2=servicecategory, 3=hostcategory',
`name` varchar(255) NOT NULL,
PRIMARY KEY (`tag_id`),
UNIQUE KEY `tags_id_type_uindex` (`id`,`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Table structure for table `resources_tags`
--
CREATE TABLE `resources_tags` (
`tag_id` bigint(20) unsigned NOT NULL,
`resource_id` bigint(20) unsigned NOT NULL,
KEY `resources_tags_resources_resource_id_fk` (`resource_id`),
KEY `resources_tags_tag_id_fk` (`tag_id`),
CONSTRAINT `resources_tags_resources_resource_id_fk` FOREIGN KEY (`resource_id`) REFERENCES `resources` (`resource_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `resources_tags_tag_id_fk` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`tag_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Table structure for table `resources`
--
CREATE TABLE `resources` (
`id` bigint unsigned NOT NULL,
`parent_id` bigint unsigned NOT NULL,
`type` tinyint unsigned NOT NULL,
`status` tinyint unsigned DEFAULT NULL,
`status_ordered` tinyint unsigned DEFAULT NULL,
`in_downtime` tinyint(1) DEFAULT 0 NOT NULL,
`acknowledged` tinyint(1) DEFAULT 0 NOT NULL,
`status_confirmed` tinyint(1) DEFAULT NULL,
`check_attempts` tinyint unsigned DEFAULT NULL,
`max_check_attempts` tinyint unsigned DEFAULT NULL,
`poller_id` bigint unsigned NOT NULL,
`severity_id` bigint unsigned,
`resource_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`id` bigint(20) unsigned NOT NULL,
`parent_id` bigint(20) unsigned NOT NULL,
`type` tinyint(3) unsigned NOT NULL COMMENT '0=service, 1=host',
`status` tinyint(3) unsigned DEFAULT NULL COMMENT 'service: 0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN, 4=PENDING\nhost: 0=UP, 1=DOWN, 2=UNREACHABLE, 4=PENDING',
`status_ordered` tinyint(3) unsigned DEFAULT NULL COMMENT '0=OK=UP\n1=PENDING\n2=UNKNOWN=UNREACHABLE\n3=WARNING\n4=CRITICAL=DOWN',
`in_downtime` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0=false, 1=true',
`acknowledged` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0=false, 1=true',
`status_confirmed` tinyint(1) DEFAULT NULL COMMENT '0=FALSE=SOFT\n1=TRUE=HARD',
`check_attempts` tinyint(3) unsigned DEFAULT NULL,
`max_check_attempts` tinyint(3) unsigned DEFAULT NULL,
`poller_id` bigint(20) unsigned NOT NULL,
`severity_id` bigint(20) unsigned DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`alias` varchar(255) DEFAULT NULL,
`address` varchar(255) DEFAULT NULL,
`parent_name` varchar(255) DEFAULT NULL,
`notes_url` varchar(255) DEFAULT NULL,
`notes` varchar(255) DEFAULT NULL,
`action_url` varchar(255) DEFAULT NULL,
`has_graph` tinyint(1) DEFAULT 0 NOT NULL,
`notifications_enabled` tinyint(1) DEFAULT 0 NOT NULL,
`passive_checks_enabled` tinyint(1) DEFAULT 0 NOT NULL,
`active_checks_enabled` tinyint(1) DEFAULT 0 NOT NULL,
`last_check_type` tinyint unsigned DEFAULT 0 NOT NULL,
`last_check` bigint unsigned DEFAULT NULL,
`output` text,
PRIMARY KEY (id, parent_id),
FOREIGN KEY (severity_id) REFERENCES severities (id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


`has_graph` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0=false, 1=true',
`notifications_enabled` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0=false, 1=true',
`passive_checks_enabled` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0=false, 1=true',
`active_checks_enabled` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0=false, 1=true',
`last_check_type` tinyint(3) unsigned NOT NULL DEFAULT 0 COMMENT '0=active check, 1=passive check',
`last_check` bigint(20) unsigned DEFAULT NULL COMMENT 'the last check timestamp',
`output` text DEFAULT NULL,
PRIMARY KEY (`resource_id`),
UNIQUE KEY `resources_id_parent_id_type_uindex` (`id`,`parent_id`,`type`),
KEY `resources_severities_severity_id_fk` (`severity_id`),
CONSTRAINT `resources_severities_severity_id_fk` FOREIGN KEY (`severity_id`) REFERENCES `severities` (`severity_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- BA / Group relations.
Expand Down
84 changes: 51 additions & 33 deletions broker/simu/docker/installBroker.sql
Original file line number Diff line number Diff line change
Expand Up @@ -705,56 +705,74 @@ UNLOCK TABLES;
-- Table structure for table `severities`
--
CREATE TABLE `severities` (
`id` bigint unsigned NOT NULL,
`name` varchar(255) DEFAULT NULL,
`severity_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`id` bigint(20) unsigned NOT NULL,
`type` tinyint(4) unsigned NOT NULL COMMENT '0=service, 1=host',
`name` varchar(255) NOT NULL,
`level` int(11) unsigned NOT NULL,
`icon_id` bigint unsigned default NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`icon_id` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`severity_id`),
UNIQUE KEY `severities_id_type_uindex` (`id`,`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


--
-- Table structure for table `tags`
--
CREATE TABLE `tags` (
`id` bigint unsigned NOT NULL,
`name` varchar(255) DEFAULT NULL,
`type` int(11) unsigned NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`tag_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`id` bigint(20) unsigned NOT NULL,
`type` tinyint(3) unsigned NOT NULL COMMENT '0=servicegroup, 1=hostgroup, 2=servicecategory, 3=hostcategory',
`name` varchar(255) NOT NULL,
PRIMARY KEY (`tag_id`),
UNIQUE KEY `tags_id_type_uindex` (`id`,`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Table structure for table `resources_tags`
--
CREATE TABLE `resources_tags` (
`tag_id` bigint(20) unsigned NOT NULL,
`resource_id` bigint(20) unsigned NOT NULL,
KEY `resources_tags_resources_resource_id_fk` (`resource_id`),
KEY `resources_tags_tag_id_fk` (`tag_id`),
CONSTRAINT `resources_tags_resources_resource_id_fk` FOREIGN KEY (`resource_id`) REFERENCES `resources` (`resource_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `resources_tags_tag_id_fk` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`tag_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Table structure for table `resources`
--
CREATE TABLE `resources` (
`id` bigint unsigned NOT NULL,
`parent_id` bigint unsigned NOT NULL,
`type` tinyint unsigned NOT NULL,
`status` tinyint unsigned DEFAULT NULL,
`status_ordered` tinyint unsigned DEFAULT NULL,
`in_downtime` tinyint(1) DEFAULT 0 NOT NULL,
`acknowledged` tinyint(1) DEFAULT 0 NOT NULL,
`status_confirmed` tinyint(1) DEFAULT NULL,
`check_attempts` tinyint unsigned DEFAULT NULL,
`max_check_attempts` tinyint unsigned DEFAULT NULL,
`poller_id` bigint unsigned NOT NULL,
`severity_id` bigint unsigned,
`resource_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`id` bigint(20) unsigned NOT NULL,
`parent_id` bigint(20) unsigned NOT NULL,
`type` tinyint(3) unsigned NOT NULL COMMENT '0=service, 1=host',
`status` tinyint(3) unsigned DEFAULT NULL COMMENT 'service: 0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN, 4=PENDING\nhost: 0=UP, 1=DOWN, 2=UNREACHABLE, 4=PENDING',
`status_ordered` tinyint(3) unsigned DEFAULT NULL COMMENT '0=OK=UP\n1=PENDING\n2=UNKNOWN=UNREACHABLE\n3=WARNING\n4=CRITICAL=DOWN',
`in_downtime` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0=false, 1=true',
`acknowledged` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0=false, 1=true',
`status_confirmed` tinyint(1) DEFAULT NULL COMMENT '0=FALSE=SOFT\n1=TRUE=HARD',
`check_attempts` tinyint(3) unsigned DEFAULT NULL,
`max_check_attempts` tinyint(3) unsigned DEFAULT NULL,
`poller_id` bigint(20) unsigned NOT NULL,
`severity_id` bigint(20) unsigned DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`alias` varchar(255) DEFAULT NULL,
`address` varchar(255) DEFAULT NULL,
`parent_name` varchar(255) DEFAULT NULL,
`notes_url` varchar(255) DEFAULT NULL,
`notes` varchar(255) DEFAULT NULL,
`action_url` varchar(255) DEFAULT NULL,
`has_graph` tinyint(1) DEFAULT 0 NOT NULL,
`notifications_enabled` tinyint(1) DEFAULT 0 NOT NULL,
`passive_checks_enabled` tinyint(1) DEFAULT 0 NOT NULL,
`active_checks_enabled` tinyint(1) DEFAULT 0 NOT NULL,
`last_check_type` tinyint unsigned DEFAULT 0 NOT NULL,
`last_check` bigint unsigned DEFAULT NULL,
`output` text,
PRIMARY KEY (id, parent_id),
FOREIGN KEY (severity_id) REFERENCES severities (id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`has_graph` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0=false, 1=true',
`notifications_enabled` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0=false, 1=true',
`passive_checks_enabled` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0=false, 1=true',
`active_checks_enabled` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0=false, 1=true',
`last_check_type` tinyint(3) unsigned NOT NULL DEFAULT 0 COMMENT '0=active check, 1=passive check',
`last_check` bigint(20) unsigned DEFAULT NULL COMMENT 'the last check timestamp',
`output` text DEFAULT NULL,
PRIMARY KEY (`resource_id`),
UNIQUE KEY `resources_id_parent_id_type_uindex` (`id`,`parent_id`,`type`),
KEY `resources_severities_severity_id_fk` (`severity_id`),
CONSTRAINT `resources_severities_severity_id_fk` FOREIGN KEY (`severity_id`) REFERENCES `severities` (`severity_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class conflict_manager {
std::unordered_map<std::pair<uint64_t, std::string>, metric_info>
_metric_cache;
std::mutex _metric_cache_m;
absl::flat_hash_map<std::pair<uint64_t, uint16_t>, uint64_t> _severity_cache;

std::unordered_set<uint32_t> _hostgroup_cache;
std::unordered_set<uint32_t> _servicegroup_cache;
Expand Down Expand Up @@ -260,7 +261,7 @@ class conflict_manager {
database::mysql_stmt _service_group_member_insert;
database::mysql_stmt _service_insupdate;
database::mysql_stmt _service_status_update;
database::mysql_stmt _severity_insupdate;
database::mysql_stmt _severity_insert;
database::mysql_stmt _severity_update;
database::mysql_stmt _severity_delete;
database::mysql_stmt _tag_insupdate;
Expand Down
Loading

0 comments on commit 4bdd805

Please sign in to comment.