diff --git a/.vitepress/config.mts b/.vitepress/config.mts index c3ec39a..97eca27 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -93,7 +93,7 @@ export default defineConfig({ { text: 'CGI Configuration File Options', link: '/documentation/usersguide/configcgi' }, { text: 'Authentication And Authorization CGIs', link: '/documentation/usersguide/cgiauth' }, { text: 'Plugins', link: '/documentation/usersguide/plugins' }, - + { text: 'Macros', link: '/documentation/usersguide/macros' }, { text: 'Naemon Logo', link: '/logo' } ] }, diff --git a/.vitepress/theme/naemon.css b/.vitepress/theme/naemon.css index a1790ea..f9cd900 100644 --- a/.vitepress/theme/naemon.css +++ b/.vitepress/theme/naemon.css @@ -9,8 +9,8 @@ --vp-home-hero-name-color: transparent; --vp-home-hero-name-background: -webkit-linear-gradient(-45deg, #4FC3F7 50%, var(--vp-c-brand-1)); - - --vp-home-hero-image-background-image: linear-gradient(45deg, var(--vp-c-brand-2) 50%, var(--vp-c-brand-1) 50%); + + --vp-home-hero-image-background-image: linear-gradient(45deg, var(--vp-c-brand-2) 50%, var(--vp-c-brand-1) 50%); --vp-home-hero-image-filter: blur(68px); --red-light: #D73A49; @@ -23,11 +23,11 @@ } .text-red { - color: var(--red-light); + color: var(--red-light) !important; } .dark .text-red { - color: var(--red-dark); + color: var(--red-dark) !important; } /* Adds a background color to images to be better visible */ diff --git a/legacy/documentation/usersguide/macros.md b/src/documentation/usersguide/macros.md similarity index 56% rename from legacy/documentation/usersguide/macros.md rename to src/documentation/usersguide/macros.md index 6abbdea..241aee3 100644 --- a/legacy/documentation/usersguide/macros.md +++ b/src/documentation/usersguide/macros.md @@ -1,55 +1,60 @@ ---- -layout: doctoc -title: Understanding Macros and How They Work ---- +# Understanding Macros and How They Work - See Also: List of Available Macros - - -### Macros +## Macros One of the main features that make Naemon so flexible is the ability to use macros in command definitions. Macros allow you to reference information from hosts, services, and other sources in your commands. -### Macro Substitution - How Macros Work +## Macro Substitution - How Macros Work Before Naemon executes a command, it will replace any macros it finds in the command definition with their corresponding values. This macro substitution occurs for all types of commands that Naemon executes - host and service checks, notifications, event handlers, etc. Certain macros may themselves contain other macros. -These include the $HOSTNOTES$, $HOSTNOTESURL$, $HOSTACTIONURL$, $SERVICENOTES$, $SERVICENOTESURL$, and $SERVICEACTIONURL$ macros. +These include the `$HOSTNOTES$`, `$HOSTNOTESURL$`, `$HOSTACTIONURL$`, `$SERVICENOTES$`, `$SERVICENOTESURL$`, and `$SERVICEACTIONURL$` macros. -### Example 1: Host Address Macro +## Example 1: Host Address Macro When you use host and service macros in command definitions, they refer to values for the host or service for which the command is being run. Let's try an example. -Assuming we are using a host definition and a check_ping command defined like this: +Assuming we are using a host definition and a `check_ping` command defined like this: -
++the expanded/final command line to be executed for the host's check command would look like this: -++define host { host_name linuxbox - address 192.168.1.2 + address 192.168.1.2 check_command check_ping ... } +
+define command { command_name check_ping - command_line /usr/lib/naemon/plugins/check_ping -H $HOSTADDRESS$ -w 100.0,90% -c 200.0,60% + command_line /usr/lib/naemon/plugins/check_ping -H $HOSTADDRESS$ -w 100.0,90% -c 200.0,60% } +
- /usr/lib/naemon/plugins/check_ping -H 192.168.1.2 -w 100.0,90% -c 200.0,60% +++ Pretty simple, right? The beauty in this is that you can use a single command definition to check an unlimited @@ -58,50 +63,65 @@ host's address is automatically substituted in the command line before execution -### Example 2: Command Argument Macros +## Example 2: Command Argument Macros You can pass arguments to commands as well, which is quite handy if you'd like to keep your command definitions rather generic. Arguments are specified in the object (i.e. host or service) definition, by separating them from the command name with -exclamation points (!) like so: +exclamation points (`!`) like so: -+++/usr/lib/naemon/plugins/check_ping -H 192.168.1.2 -w 100.0,90% -c 200.0,60% +
+++ In the example above, the service check command has two arguments (which can be referenced -with $ARGn$ macros). The $ARG1$ macro will be -"200.0,80%" and $ARG2$ will be "400.0,40%" +with [`$ARGn$`](macrolist#arg) macros). The `$ARG1$` macro will be +"200.0,80%" and `$ARG2$` will be "400.0,40%" (both without quotes). Assuming we are using the host definition given -earlier and a check_ping command defined like this: +earlier and a `check_ping` command defined like this: -++define service { host_name linuxbox service_description PING - check_command check_ping!200.0,80%!400.0,40% + check_command check_ping!200.0,80%!400.0,40% ... } +
+++ the expanded/final command line to be executed for the service's check command would look like this: -++define command { command_name check_ping - command_line /usr/lib/naemon/plugins/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ + command_line /usr/lib/naemon/plugins/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ } +
- /usr/lib/naemon/plugins/check_ping -H 192.168.1.2 -w 200.0,80% -c 400.0,40% ++-{{ site.hint }}If you need to pass bang (!) characters in your command arguments, you can do so by escaping them with a backslash (\).{{ site.end }} +> [!TIP] +> If you need to pass bang (`!`) characters in your command arguments, you can do so by escaping them with a backslash (`\`). If you need to include backslashes in your command arguments, they should also be escaped with a backslash. -### On-Demand Macros +## On-Demand Macros Normally when you use host and service macros in command definitions, they refer to values for the host or service for which the command is being run. For instance, if a host -check command is being executed for a host named "linuxbox", all the standard host macros will +check command is being executed for a host named "linuxbox", all the [standard host macros](macrolist) will refer to values for that host ("linuxbox"). If you would like to reference values for another host or service in a command (for which the command is @@ -115,34 +135,43 @@ they should get their value. Here's the basic format for on-demand macros: Replace HOSTMACRONAME and SERVICEMACRONAME with the name of one of the standard host -of service macros found here. +of service macros found [here](macrolist). Note that the macro name is separated from the host or service identifier by a colon (:). For on-demand service macros, the service identifier consists of both a host name and a service description - these are separated by a colon (:) as well. -{{ site.hint }}On-demand service macros can contain an empty host name field. In this case the name of the host associated with the service will automatically be used.{{ site.end }} +> [!TIP] +> On-demand service macros can contain an empty host name field. In this case the name of the host associated with the service will automatically be used. Examples of on-demand host and service macros follow: -+++/usr/lib/naemon/plugins/check_ping -H 192.168.1.2 -w 200.0,80% -c 400.0,40% +
++On-demand macros are also available for hostgroup, servicegroup, contact, and contactgroup macros. For example: -++$HOSTDOWNTIME:myhost$ <--- On-demand host macro $SERVICESTATEID:novellserver:DS Database$ <--- On-demand service macro $SERVICESTATEID::CPU Load$ <--- On-demand service macro with blank host name field +
++-### On-Demand Group Macros +## On-Demand Group Macros You can obtain the values of a macro across all contacts, hosts, or services in a specific group by using a special format for your on-demand macro declaration. @@ -156,76 +185,85 @@ in an on-demand macro, like so: Replace HOSTMACRONAME, SERVICEMACRONAME, and CONTACTMACRONAME with -the name of one of the standard host, service, or contact macros found here. +the name of one of the standard host, service, or contact macros found [here](macrolist). The delimiter you specify is used to separate macro values for each group member. For example, the following macro will return a comma-separated list of host state ids for hosts that are members of the hg1 hostgroup: -++$CONTACTEMAIL:john$ <--- On-demand contact macro $CONTACTGROUPMEMBERS:linux-admins$ <--- On-demand contactgroup macro $HOSTGROUPALIAS:linux-servers$ <--- On-demand hostgroup macro $SERVICEGROUPALIAS:DNS-Cluster$ <--- On-demand servicegroup macro +
++This macro definition will return something that looks like this: -++$HOSTSTATEID:hg1:,$ +
++-### Custom Variable Macros +## Custom Variable Macros -Any custom object variables that you define in host, +Any [custom object variables](customobjectvars) that you define in host, service, or contact definitions are also available as macros. Custom variable macros are named as follows: -++0,2,1,1,0,0,2 +
++-The `_MACADDRESS` custom variable would be available in a macro called `$_HOSTMACADDRESS$`. -More information on custom object variables and how they can be used in macros can be found here. +The `_MACADDRESS` custom variable would be available in a macro called `$_HOSTMACADDRESS$`. +More information on custom object variables and how they can be used in macros can be found [here](customobjectvars). -### Macro Cleansing +## Macro Cleansing Some macros are stripped of potentially dangerous shell metacharacters before being substituted into commands to be executed. Which characters are stripped from the macros depends on the setting of -the `illegal_macro_output_chars` directive. +the [`illegal_macro_output_chars`](configmain#illegal_macro_output_chars) directive. The following macros are stripped of potentially dangerous characters: -++define host { host_name linuxbox address 192.168.1.1 - _MACADDRESS 00:01:02:03:04:05 + _MACADDRESS 00:01:02:03:04:05 ... } +
-
+1. [`$HOSTOUTPUT$`](macrolist#hostoutput) +2. [`$LONGHOSTOUTPUT$`](macrolist#longhostoutput) +3. [`$HOSTPERFDATA$`](macrolist#hostperfdata) +4. [`$HOSTACKAUTHOR$`](macrolist#hostackauthor) +5. [`$HOSTACKCOMMENT$`](macrolist#hostackcomment) +6. [`$SERVICEOUTPUT$`](macrolist#serviceoutput) +7. [`$LONGSERVICEOUTPUT$`](macrolist#longserviceoutput) +8. [`$SERVICEPERFDATA$`](macrolist#serviceperfdata) +9. [`$SERVICEACKAUTHOR$`](macrolist#serviceackauthor) +10. [`$SERVICEACKCOMMENT$`](macrolist#serviceackcomment) -Additionally, any macros that contain custom variables are stripped for safety and security. +Additionally, any macros that contain [custom variables](customobjectvars) are stripped for safety and security. -### Macros as Environment Variables +## Macros as Environment Variables Since Naemon macros are no longer available in the environment for performance reasons. Its a huge waste of resources to calculate all macros all the time even if they are not used. @@ -235,18 +273,22 @@ can edit your command to export specific macros. Example notification command: -- $HOSTOUTPUT$
-- $LONGHOSTOUTPUT$
-- $HOSTPERFDATA$
-- $HOSTACKAUTHOR$
-- $HOSTACKCOMMENT$
-- $SERVICEOUTPUT$
-- $LONGSERVICEOUTPUT$
-- $SERVICEPERFDATA$
-- $SERVICEACKAUTHOR$
-- $SERVICEACKCOMMENT$
-++This way you can define whatever environment macro you need and only those are calculated on runtime. -### Available Macros +## Available Macros A list of all the macros that are available in Naemon, as well as -a chart of when they can be used, can be found here. +a chart of when they can be used, can be found [here](macrolist). diff --git a/src/documentation/usersguide/toc.md b/src/documentation/usersguide/toc.md index c9a4a7c..b0974e7 100644 --- a/src/documentation/usersguide/toc.md +++ b/src/documentation/usersguide/toc.md @@ -81,7 +81,7 @@ [Plugins](plugins) :white_check_mark: -[Macros and how they work](macros) +[Macros and how they work](macros) :white_check_mark: [Standard macros available in Naemon](macrolist)++define command { command_name my_old_notification_script - command_line NAGIOS_HOSTNAME="$HOSTNAME$" /usr/local/bin/notifiy.pl ... + command_line NAGIOS_HOSTNAME="$HOSTNAME$" /usr/local/bin/notifiy.pl ... } +