Skip to content

Commit

Permalink
Mon 34554 ba kpi 22.10 (#1114)
Browse files Browse the repository at this point in the history
* Empty-Commit

* fix(broker/bam): kpi update is better now.

* enh(tests): new test

* fix(tests): ba tests are better but still not running

* fix(tests): bam tests are good

* fix(tests): wip

* Empty-Commit

* enh(bam): const replaced by constexpr in two places

---------

Co-authored-by: tuntoja <[email protected]>
  • Loading branch information
bouda1 and tuntoja authored Feb 6, 2024
1 parent 2eb2e39 commit 2243eec
Show file tree
Hide file tree
Showing 29 changed files with 855 additions and 475 deletions.
36 changes: 19 additions & 17 deletions bbdo/bam/ba_event.cc
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
** Copyright 2014-2015, 2021 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 2014-2015, 2021 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 "bbdo/bam/ba_event.hh"

Expand All @@ -30,7 +30,9 @@ ba_event::ba_event()
: io::data(ba_event::static_type()),
ba_id(0),
first_level(0),
end_time(-1),
in_downtime(false),
start_time(-1),
status(3) {}

/**
Expand Down
34 changes: 17 additions & 17 deletions bbdo/bam/ba_event.hh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
** Copyright 2014 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 2014 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]
*/

#ifndef CCB_BAM_BA_EVENT_HH
#define CCB_BAM_BA_EVENT_HH
Expand Down
21 changes: 16 additions & 5 deletions broker/bam/inc/com/centreon/broker/bam/ba.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class ba : public computable, public service_listener {
std::unique_ptr<inherited_downtime> _inherited_downtime;
std::vector<std::shared_ptr<ba_event>> _initial_events;

void _open_new_event(io::stream* visitor, short service_hard_state);
void _open_new_event(io::stream* visitor,
com::centreon::broker::bam::state service_hard_state);
void _compute_inherited_downtime(io::stream* visitor);
void _commit_initial_events(io::stream* visitor);

Expand Down Expand Up @@ -101,10 +102,20 @@ class ba : public computable, public service_listener {
configuration::ba::dt_ignore};
int _recompute_count{0};

static double _normalize(double d);
virtual bool _apply_impact(kpi* kpi_ptr, impact_info& impact) = 0;
static constexpr double _normalize(double d) {
if (d > 100.0)
d = 100.0;
else if (d < 0.0)
d = 0.0;
return d;
}

virtual void _apply_impact(kpi* kpi_ptr, impact_info& impact) = 0;
virtual void _unapply_impact(kpi* kpi_ptr, impact_info& impact) = 0;
virtual void _recompute();
virtual bool _apply_changes(kpi* child,
const impact_values& new_hard_impact,
const impact_values& new_soft_impact,
bool in_downtime) = 0;
std::shared_ptr<ba_status> _generate_ba_status(bool state_changed) const;
std::shared_ptr<io::data> _generate_virtual_service_status() const;

Expand All @@ -126,7 +137,7 @@ class ba : public computable, public service_listener {
uint32_t get_id() const;
uint32_t get_host_id() const;
uint32_t get_service_id() const;
bool get_in_downtime() const;
bool in_downtime() const;
timestamp get_last_kpi_update() const;
std::string const& get_name() const;
virtual std::string get_output() const = 0;
Expand Down
43 changes: 22 additions & 21 deletions broker/bam/inc/com/centreon/broker/bam/ba_best.hh
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 2022-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]
*/

#ifndef CCB_BAM_BA_BEST_HH
#define CCB_BAM_BA_BEST_HH
Expand Down Expand Up @@ -43,12 +43,13 @@ class ba_best : public ba {

void _commit_initial_events(io::stream* visitor);

std::vector<std::shared_ptr<ba_event> > _initial_events;

protected:
bool _apply_impact(kpi* kpi_ptr, impact_info& impact) override;
void _apply_impact(kpi* kpi_ptr, impact_info& impact) override;
void _unapply_impact(kpi* kpi_ptr, impact_info& impact) override;
void _recompute() override;
bool _apply_changes(kpi* child,
const impact_values& new_hard_impact,
const impact_values& new_soft_impact,
bool in_downtime) override;

public:
ba_best(uint32_t id,
Expand Down
42 changes: 24 additions & 18 deletions broker/bam/inc/com/centreon/broker/bam/ba_impact.hh
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 2022-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]
*/

#ifndef CCB_BAM_BA_IMPACT_HH
#define CCB_BAM_BA_IMPACT_HH
Expand All @@ -35,9 +35,15 @@ class kpi;
* of value.
*/
class ba_impact : public ba {
void _recompute();

protected:
bool _apply_impact(kpi* kpi_ptr, impact_info& impact) override;
void _apply_impact(kpi* kpi_ptr, impact_info& impact) override;
void _unapply_impact(kpi* kpi_ptr, impact_info& impact) override;
bool _apply_changes(kpi* child,
const impact_values& new_hard_impact,
const impact_values& new_soft_impact,
bool in_downtime) override;

public:
ba_impact(uint32_t id,
Expand Down
41 changes: 22 additions & 19 deletions broker/bam/inc/com/centreon/broker/bam/ba_ratio_number.hh
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 2022-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]
*/

#ifndef CCB_BAM_BA_RATIO_NUMBER_HH
#define CCB_BAM_BA_RATIO_NUMBER_HH
Expand All @@ -35,9 +35,12 @@ class kpi;
* of value.
*/
class ba_ratio_number : public ba {
bool _apply_impact(kpi* kpi_ptr, impact_info& impact) override;
void _apply_impact(kpi* kpi_ptr, impact_info& impact) override;
void _unapply_impact(kpi* kpi_ptr, impact_info& impact) override;
void _recompute() override;
bool _apply_changes(kpi* child,
const impact_values& new_hard_impact,
const impact_values& new_soft_impact,
bool in_downtime) override;

public:
ba_ratio_number(uint32_t id,
Expand Down
41 changes: 22 additions & 19 deletions broker/bam/inc/com/centreon/broker/bam/ba_ratio_percent.hh
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 2022-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]
*/

#ifndef CCB_BAM_BA_RATIO_PERCENT_HH
#define CCB_BAM_BA_RATIO_PERCENT_HH
Expand All @@ -35,9 +35,12 @@ class kpi;
* of value.
*/
class ba_ratio_percent : public ba {
bool _apply_impact(kpi* kpi_ptr, ba::impact_info& impact) override;
void _apply_impact(kpi* kpi_ptr, ba::impact_info& impact) override;
void _unapply_impact(kpi* kpi_ptr, ba::impact_info& impact) override;
void _recompute() override;
bool _apply_changes(kpi* child,
const impact_values& new_hard_impact,
const impact_values& new_soft_impact,
bool in_downtime) override;

public:
ba_ratio_percent(uint32_t id,
Expand Down
Loading

0 comments on commit 2243eec

Please sign in to comment.