Depends on what you want to do with the macro, really. Is this for something outside of Core or XI? Cause you can always just pass
$HOSTADDRESS$ to a script and perform the regex there and do whatever you wanted with it.
But if you want to really make your own macro, here are the steps. I'm using the master branch of nagioscore (
https://www.github.com/NagiosEnterprises/nagioscore/):
1. Think of a name for it. We'll call ours
$HOSTADDRESSADJUSTED$
2. We need to add it to
common/macros.c and
include/macros.h
3. Open
include/macros.h and add our definition to the end of the macro list (line 226):
Code: Select all
#define MACRO_HOSTADDRESSADJUSTED 163
4. Increment the definition for
MACRO_X_COUNT:
Change this line:
Code: Select all
#define MACRO_X_COUNT 163 /* size of macro_x[] array */
To this:
Code: Select all
#define MACRO_X_COUNT 164 /* size of macro_x[] array */
5. Open
common/macros.c and look for the function
add_macrox_name() (line 2673). Add our macro to the bottom of the initialization list. (line 2845).
Code: Select all
add_macrox_name(HOSTADDRESSADJUSTED);
6. Find the
grab_macrox_value_r() function (line 658). Add our macro to the switch statement, directly after
MACRO_HOSTNOTIFICATIONPERIOD (line 757).
So change these lines:
Code: Select all
case MACRO_HOSTIMPORTANCE:
case MACRO_HOSTANDSERVICESIMPORTANCE:
case MACRO_HOSTNOTIFICATIONENABLED:
case MACRO_HOSTNOTIFICATIONPERIOD:
/* a standard host macro */
if(arg2 == NULL) {
To this:
Code: Select all
case MACRO_HOSTIMPORTANCE:
case MACRO_HOSTANDSERVICESIMPORTANCE:
case MACRO_HOSTNOTIFICATIONENABLED:
case MACRO_HOSTNOTIFICATIONPERIOD:
case MACRO_HOSTADDRESSADJUSTED:
/* a standard host macro */
if(arg2 == NULL) {
7. Now find the function
grab_standard_host_macro_r() (if you've followed the above steps, this should be line 1603 now). This is where our magic will happen. To keep it easy, instead of adding to the bottom of the switch statement, we're going to add it right after the current
HOSTADDRESS (breaks on line 1643).
So change these lines:
Code: Select all
case MACRO_HOSTALIAS:
*output = temp_host->alias;
break;
case MACRO_HOSTADDRESS:
*output = temp_host->address;
break;
#ifdef NSCORE
To this (
IT HAS TO BE INSIDE THE #ifdef NSCORE BLOCK!!!):
Code: Select all
case MACRO_HOSTALIAS:
*output = temp_host->alias;
break;
case MACRO_HOSTADDRESS:
*output = temp_host->address;
break;
#ifdef NSCORE
case MACRO_HOSTADDRESSADJUSTED:
buf1 = temp_host->address;
/* your code goes here */
*output = mkstr("%s", buf1);
free(buf1);
break;
8. Recompile nagioscore (
./configure && make all && make install) (
https://assets.nagios.com/downloads/nag ... Source.pdf)
9. Enjoy your new macro
