Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature global notification handler #477

Merged
merged 6 commits into from
Sep 30, 2024

Conversation

sni
Copy link
Contributor

@sni sni commented Sep 12, 2024

Add global notification handler in the same way as global event handlers. It adds 2 new
global options:

  • global_host_notification_handler=global-host-notify
  • global_service_notification_handler=global-service-notify

which will be run each time a normal notification would be considered. It does not require
contacts for hosts and services. If used it will also prevent warnings if hosts/services do
not have contacts set.
The global notification handlers do not have any contact macros set, because they are independent of contacts.

This PR also adds another global option:

  • log_global_notifications

This option can be used to suppress a log entry each time the global notification handler is run.

Finally this PR adds a new generic external command

  • LOG

It can be used to add custom log entries to the main naemon log file. For example to add the
actual notified contacts to the log file.

ex.:

printf "[%lu] LOG;SERVICE NOTIFICATION: test contact;testhost;test service;CRITICAL;notify-by-email;test message\n" `date +%s` >> .../tmp/run/naemon.cmd

which would add a log entry similar to a normal notification. The actual hosts/services/contacts and commands don't have to exist.

Or other notes like ex.:

printf "[%lu] LOG;SERVICE NOTE: testhost;event handler restarted service successfully\n" `date +%s` >> .../tmp/run/naemon.cmd

@sni sni force-pushed the feature_global_notification_handler branch from 08fc5e0 to 3674648 Compare September 13, 2024 06:59
global notification handler are like global event handler. They are fired each time
a notification would be sent out (regardless whether there is a contact or not)

    global_host_notification_handler=somecommand
    global_service_notification_handler=somecommand

global notification handler work like normal notifications, except they don't have contact
related macros set.
the global notification handler adds quite some noise to the log file, so
make it possible to disable it.
This generic LOG command can be used to add entries to the main logfile. It is
useful ex.: from a global notification handler to log the actual notified contacts.
@sni sni force-pushed the feature_global_notification_handler branch from 3674648 to d671fe1 Compare September 13, 2024 12:34
@@ -1455,7 +1497,7 @@ int pre_flight_object_check(int *w, int *e)
}

/* check to see if there is at least one contact/group */
if (temp_service->contacts == NULL && temp_service->contact_groups == NULL) {
if (temp_service->contacts == NULL && temp_service->contact_groups == NULL && global_service_event_handler == NULL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be probably global_service_notification_handler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, you are totally right

@@ -47,6 +47,7 @@
#define DEFAULT_LOG_CURRENT_STATES 1 /* log current service and host states after rotating log */
#define DEFAULT_LOG_EXTERNAL_COMMANDS 1 /* log external commands */
#define DEFAULT_LOG_PASSIVE_CHECKS 1 /* log passive service checks */
#define DEFAULT_log_global_notifications 1 /* log global notifications */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we uppercase this please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am pretty sure it was uppercase initially :-) Will fix it again

@@ -39,6 +39,7 @@

#define NSLOG_HOST_NOTIFICATION 524288
#define NSLOG_SERVICE_NOTIFICATION 1048576
#define NSLOG_EXT_CUSTOM 2097152
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove one \t so all numbers line up nicely

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks aligned too me with ts=4. But i can replace all tabs in that file with spaces, but that'll be an extra commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like every editor has it's own opinion on that.
It's sort of aligned on the GitHub Website, but in VS Code the numbers are all over the place.

I guess your suggestion is the best option :)

grafik

free(nj);
}

/* @todo Handle nebmod stuff when getting results from workers */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still relevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it...

@nook24 nook24 added Approved and removed Approved labels Sep 30, 2024
nook24 added a commit to it-novum/naemon.github.io that referenced this pull request Sep 30, 2024
align constants with spaces
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@sni sni merged commit 1546298 into naemon:master Sep 30, 2024
32 checks passed
@sni sni deleted the feature_global_notification_handler branch September 30, 2024 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants