From 25dc86881acff34beb67ab5cac31ff346147dea4 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 12 Feb 2014 11:49:38 +0100 Subject: [PATCH] Make script variables constant. Fixes #5446 --- doc/2.6-running-icinga-2.md | 6 +++--- doc/3.03-macros.md | 8 ++++---- doc/4.1-configuration-syntax.md | 15 +++++++-------- doc/4.2-global-variables.md | 4 ++-- icinga-app/icinga.cpp | 2 +- lib/config/config_parser.yy | 4 +--- 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/doc/2.6-running-icinga-2.md b/doc/2.6-running-icinga-2.md index bcbbdfa1c..b338b8e22 100644 --- a/doc/2.6-running-icinga-2.md +++ b/doc/2.6-running-icinga-2.md @@ -32,7 +32,7 @@ Icinga 2's init script is installed in `/etc/init.d/icinga2` by default: -V [ --version ] show version information -l [ --library ] arg load a library -I [ --include ] arg add include search directory - -D [ --define] args define a variable + -D [ --define] args define a constant -c [ --config ] arg parse a configuration file -C [ --validate ] exit after validating the configuration -x [ --debug ] enable debugging @@ -50,9 +50,9 @@ Icinga 2's init script is installed in `/etc/init.d/icinga2` by default: Instead of loading libraries using the [`library` config directive](#library) you can also use the `--library` command-line option. -#### Variables +#### Constants -[Global variables](#global-variables) can be set using the `--define` command-line option. +[Global constants](#global-constants) can be set using the `--define` command-line option. #### Config Include Path diff --git a/doc/3.03-macros.md b/doc/3.03-macros.md index 84e1ad00b..cbea18376 100644 --- a/doc/3.03-macros.md +++ b/doc/3.03-macros.md @@ -3,7 +3,7 @@ > **Note** > -> There is a limited set of special [global variables](#global-variables) which can be re-used and +> There is a limited set of special [global constants](#global-constants) which can be re-used and > also partly overridden such as `IcingaEnableChecks`. ### Runtime Macros @@ -64,7 +64,7 @@ up macros: 2. Service object 3. Host object 4. Command object -5. Global macros in the IcingaMacros variable +5. Global macros in the IcingaMacros constant This execution order allows you to define default values for macros in your command objects. The `my-ping` command shown above uses this to set default @@ -262,7 +262,7 @@ when passing credentials to database checks: ### Configuration Macros -Icinga 2 allows you to define constant variables which can be used in a limited +Icinga 2 allows you to define constants which can be used in a limited scope. For example, constant expressions can reference a pre-defined global constant variable and calculate a value for the service check interval. @@ -276,4 +276,4 @@ Example: check_interval = (MyCheckInterval / 2.5) } -More details in the chapter [Constant Expressions](#constant-expressions). \ No newline at end of file +More details in the chapter [Constant Expressions](#constant-expressions). diff --git a/doc/4.1-configuration-syntax.md b/doc/4.1-configuration-syntax.md index d31a614c3..a0c3795aa 100644 --- a/doc/4.1-configuration-syntax.md +++ b/doc/4.1-configuration-syntax.md @@ -296,21 +296,20 @@ dictionary by exiplicitely overriding their value with `null`. services["ping6"] = null -### Variables +### Constants -Global variables can be set using the `var` and `const` keywords: +Global constants can be set using the `const` keyword: - var VarName = "some value" + const VarName = "some value" The value can be a string, number, array or a dictionary. -Variables can be set multiple times unless they were introduced using -the `const` keyword. +Constants cannot be changed once they are set. > **Note** > -> The `set` keyword is an alias for the `var` keyword and is available -> in order to provide compatibility with older versions. Its use is +> The `set` and `var` keywords are an alias for `const` and are available +> in order to provide compatibility with older versions. Their use is > deprecated. ### Constant Expressions @@ -328,7 +327,7 @@ overridden by grouping expressions using parentheses: check_interval ((15 * 60) / 2) } -Global variables may be used in constant expressions. +Global constants may be used in constant expressions. var MyCheckInterval = 10m diff --git a/doc/4.2-global-variables.md b/doc/4.2-global-variables.md index 98c82c856..eb9560504 100644 --- a/doc/4.2-global-variables.md +++ b/doc/4.2-global-variables.md @@ -1,6 +1,6 @@ -## Global Variables +## Global Constants -Icinga 2 provides a number of special global variables: +Icinga 2 provides a number of special global constants. Some of them can be overriden using the `--define` command line parameter: Variable |Description --------------------------|------------------- diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 66af81175..33a87b9e2 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -209,7 +209,7 @@ int main(int argc, char **argv) ("version,V", "show version information") ("library,l", po::value >(), "load a library") ("include,I", po::value >(), "add include search directory") - ("define,D", po::value >(), "define a variable") + ("define,D", po::value >(), "define a constant") ("config,c", po::value >(), "parse a configuration file") ("no-config,z", "start without a configuration file") ("validate,C", "exit after validating the configuration") diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index 9102c1dbd..122d8bb77 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -203,9 +203,7 @@ variable: variable_decl identifier T_EQUAL value } ScriptVariable::Ptr sv = ScriptVariable::Set($2, *value); - - if (!$1) - sv->SetConstant(true); + sv->SetConstant(true); free($2); delete value; -- 2.40.0