custom fields from notificationauthor contact

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
rniesten
Posts: 4
Joined: Mon Sep 03, 2018 10:16 am
Location: Maastricht

custom fields from notificationauthor contact

Post by rniesten »

We send notifications to Slack to a specific channel (#notifications). One contact (slack) is configured for this purpose and configured as contact for all relevant services. In case of an acknowledge, I would like to tag the notification author which requires a UID from Slack.
For this purpose I added a customized field _SLACKID to each contact. Because the notification contact is "slack", I can't use the $_CONTACTSLACKID$ in the notification command (which caused a warning and didn't work either).

Code: Select all

define contact{
    contact_name                    slack                   ; Short name of user
    use                             generic-contact         ; Inherit default values from datahub-contact
    alias                           Slack Alert User        ; Full name of user
    service_notification_commands   notify-service-by-slack	; send service notifications to slack
    host_notification_commands      notify-host-by-slack	; send host notifications to slack
    _SLACKID                       N/A         ; Slack User ID
}

define contact{
    use                             generic-contact   ; Inherit default values from generic-contact template (defined above)
    contact_name                    user1          ; Short name of user
    alias                           First Lastname     ; full name
    email                           [email protected]
    _SLACKID                       UC1AB2C3D         ; Slack User ID
}
$_CONTACTSLACKID:user1$ works fine, so using on-demand macros with variable references would exactly meet my goals.
Unfortunately this doesn't work (at least I couldn't get it working...)

$_CONTACTSLACKID:$NOTIFICATIONAUTHOR$$ doesn't work
I also tried $_CONTACTSLACKID:$NOTIFICATIONAUTHOR$, but with same result.

nagos.debug:

Code: Select all

[1536061902.178589] [2048.2] [pid=24116]   Processing part: '_CONTACTSLACKID:'
[1536061902.178598] [2048.2] [pid=24116]   Processed '_CONTACTSLACKID:', Free: 0
[1536061902.178606] [2048.0] [pid=24116]  WARNING: An error occurred processing macro '_CONTACTSLACKID:'!
[1536061902.178620] [2048.2] [pid=24116]   Non-macro.  Running output (248): '/opt/Custom-Nagios-Plugins/notify_slack.sh -t "ACKNOWLEDGEMENT" -a "Roger Niesten" -C "test message  (contactname: slack_test, contactalias: Slack Alert User for testing, author: Roger Niesten, email: $CONTACTEMAIL:$NOTIFICATIONAUTHOR$, slack-ID3: '
[1536061902.178630] [2048.2] [pid=24116]   Processing part: 'NOTIFICATIONAUTHOR'
[1536061902.178639] [2048.2] [pid=24116]   Not currently in macro.  Running output (284): '/opt/Custom-Nagios-Plugins/notify_slack.sh -t "ACKNOWLEDGEMENT" -a "Roger Niesten" -C "test message  (contactname: slack_test, contactalias: Slack Alert User for testing, author: Roger Niesten, slack-ID3: $_CONTACTSLACKID:$NOTIFICATIONAUTHOR'
Is it posible to use macros as reference and if so, how?
Is something wrong in the syntax?
Suggestions to other options to reach my goal are also welcome :-)
Thanks in advance.

Regards,
Roger
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: custom fields from notificationauthor contact

Post by scottwilkerson »

If it is just used for the slack contact and notifications commands couldn't you just change the slack commands to use?

Code: Select all

$_CONTACTSLACKID:slack$
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: custom fields from notificationauthor contact

Post by scottwilkerson »

Nevermind, that isn't going to work, I see what you are trying to do.

Maybe this

Code: Select all

$CONTACTEMAIL:`echo "$NOTIFICATIONAUTHOR$"`$
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
rniesten
Posts: 4
Joined: Mon Sep 03, 2018 10:16 am
Location: Maastricht

Re: custom fields from notificationauthor contact

Post by rniesten »

Thanks for your answer, but this doesn't work either :-(

When having a closer look in the nagios.debug file, it looks like the macro processing is completely done sequentially:

Code: Select all

[1536141647.894142] [2048.2] [pid=4724]   Processing part: 'CONTACTEMAIL:`echo "'
[1536141647.894150] [2048.2] [pid=4724]   macros[22] (CONTACTEMAIL) match.
[1536141647.894175] [2048.2] [pid=4724]   Processed 'CONTACTEMAIL:`echo "', Free: 0
[1536141647.894183] [2048.0] [pid=4724]  WARNING: An error occurred processing macro 'CONTACTEMAIL:`echo "'!
[1536141647.894191] [2048.2] [pid=4724]   Non-macro.  Running output (434): '/opt/Custom-Nagios-Plugins/notify_slack.sh -t "ACKNOWLEDGEMENT" -a "Roger Niesten" -C "testing123456789  (author: Roger Niesten, authorname: Roger Niesten, email: $CONTACTEMAIL:`echo "$NOTIFICATIONAUTHORNAME$"`$ )" -h "(#17) test-host" -g "prd-env,https-servers" -s "license" -S "CRITICAL" -o "CRITICAL - license expires in 1 days  (contactname: slack, email: '
[1536141647.894210] [2048.2] [pid=4724]   Processing part: 'NOTIFICATIONAUTHOR'
[1536141647.894219] [2048.2] [pid=4724]   Not currently in macro.  Running output (474): '/opt/Custom-Nagios-Plugins/notify_slack.sh -t "ACKNOWLEDGEMENT" -a "Roger Niesten" -C "testing123456789  (author: Roger Niesten, authorname: Roger Niesten, email: $CONTACTEMAIL:`echo "$NOTIFICATIONAUTHORNAME$"`$ )" -h "(#17) test-host" -g "prd-env,https-servers" -s "license" -S "CRITICAL" -o "CRITICAL - license expires in 1 days  (contactname: slack, email: $CONTACTEMAIL:`echo "$NOTIFICATIONAUTHOR'
[1536141647.894227] [2048.2] [pid=4724]   Processing part: '"`'
[1536141647.894236] [2048.0] [pid=4724]  WARNING: Could not find a macro matching '"`'!
[1536141647.894244] [2048.2] [pid=4724]   Processed '"`', Free: 0
[1536141647.894251] [2048.0] [pid=4724]  WARNING: An error occurred processing macro '"`'!
[1536141647.894258] [2048.2] [pid=4724]   Non-macro.  Running output (474): '/opt/Custom-Nagios-Plugins/notify_slack.sh -t "ACKNOWLEDGEMENT" -a "Roger Niesten" -C "testing123456789  (author: Roger Niesten, authorname: Roger Niesten, email: $CONTACTEMAIL:`echo "$NOTIFICATIONAUTHORNAME$"`$ )" -h "(#17) test-host" -g "prd-env,https-servers" -s "license" -S "CRITICAL" -o "CRITICAL - license expires in 1 days  (contactname: slack, email: $CONTACTEMAIL:`echo "$NOTIFICATIONAUTHOR'
How can I achief that $NOTIFICATIONAUTHOR (or `echo $NOTIFICATIONAUTHOR`) is processed BEFORE on-demand macro $CONTACTEMAIL:....$ is processed?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: custom fields from notificationauthor contact

Post by scottwilkerson »

rniesten wrote:When having a closer look in the nagios.debug file, it looks like the macro processing is completely done sequentially:
I was afraid of that. I really don't at present see a way to accomplish your goal of making the macro dynamic.

The only thing I can really suggest would be to pass in the $NOTIFICATIONAUTHOR$ and then grab the information you are looking for from the objects JSON CGI querying the contacts and grabbing the value from custom_variables

Code: Select all

/nagios/jsonquery.html
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked