Skip to content

Commit

Permalink
Filter all NEBTYPE_NOTIFICATION_START
Browse files Browse the repository at this point in the history
Filter all notifications where contacts_notified == 0
Naemon calls the broker_notification_data method for each host and service check twice.
This produces a lot of SPAM and useless data - at least for Statusengine.
For now, we are going to filter all notification data we are not interested in
  • Loading branch information
nook24 committed Sep 16, 2024
1 parent 8c7fe89 commit 80435fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/MessageHandler/MessageHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,19 @@ namespace statusengine {
*/
void SendMessage(NagiosObject &obj) override {
if (bulk) {
bulkMessages.push_back(new NagiosObject(&obj));
if (++(*globalBulkCounter) >= maxBulkSize) {
mhlist.FlushBulkQueue();
if(!obj.isEmpty()){
bulkMessages.push_back(new NagiosObject(&obj));
if (++(*globalBulkCounter) >= maxBulkSize) {
mhlist.FlushBulkQueue();
}
}
}
else {
std::string msg = obj.ToString();
for (auto &handler : *handlers) {
handler->SendMessage(queue, msg);
if(!obj.isEmpty()){
std::string msg = obj.ToString();
for (auto &handler : *handlers) {
handler->SendMessage(queue, msg);
}
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/NagiosObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ namespace statusengine {
return std::string(json_object_to_json_string(data));
}

/**
* Check if the JSON object is empty
* Objects can be empty, if the broker filters certain events
* @return true if the JSON object is empty, false otherwise
*/
bool isEmpty() const {
return json_object_object_length(data) == 0;
}

/**
* Counter will be incremented
* @return json_object*
Expand Down Expand Up @@ -504,6 +513,13 @@ namespace statusengine {
class NagiosNotificationData : public NagiosObject {
public:
explicit NagiosNotificationData(const nebstruct_notification_data *notificationData) {
if(notificationData->type == 600 || notificationData->contacts_notified == 0){
// 600 = NEBTYPE_NOTIFICATION_START
// Naemon calls the broker_notification_data nearly for every service check. This produces a lot of traffic to the broker.
// Due to we dont need the NEBTYPE_NOTIFICATION_START data, and if no contacts where notified, we drop all this data hardcoded for now.
return;
}

SetData("type", notificationData->type);
SetData("flags", notificationData->flags);
SetData("attr", notificationData->attr);
Expand Down

0 comments on commit 80435fa

Please sign in to comment.