Make script variables constant.

Fixes #5446
This commit is contained in:
Gunnar Beutner 2014-02-12 11:49:38 +01:00
parent b968850bc1
commit 25dc86881a
6 changed files with 18 additions and 21 deletions

View File

@ -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

View File

@ -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`.
### <a id="runtime-macros"></a> 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:
### <a id="configuration-macros"></a> 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).
More details in the chapter [Constant Expressions](#constant-expressions).

View File

@ -296,21 +296,20 @@ dictionary by exiplicitely overriding their value with `null`.
services["ping6"] = null
### <a id="variables"></a> Variables
### <a id="constants"></a> 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.
### <a id="constant-expressions"></a> 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

View File

@ -1,6 +1,6 @@
## <a id="global-variables"></a> Global Variables
## <a id="global-constants"></a> 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
--------------------------|-------------------

View File

@ -209,7 +209,7 @@ int main(int argc, char **argv)
("version,V", "show version information")
("library,l", po::value<std::vector<String> >(), "load a library")
("include,I", po::value<std::vector<String> >(), "add include search directory")
("define,D", po::value<std::vector<String> >(), "define a variable")
("define,D", po::value<std::vector<String> >(), "define a constant")
("config,c", po::value<std::vector<String> >(), "parse a configuration file")
("no-config,z", "start without a configuration file")
("validate,C", "exit after validating the configuration")

View File

@ -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;