The `plugin-check-command` command does not support any vars.
+By default this template is automatically imported into all CheckCommand definitions.
+
### <a id="itl-plugin-notification-command"></a> plugin-notification-command
Command template for notification scripts executed by Icinga 2.
The `plugin-notification-command` command does not support any vars.
+By default this template is automatically imported into all CheckCommand definitions.
+
### <a id="itl-plugin-event-command"></a> plugin-event-command
Command template for event handler scripts executed by Icinga 2.
The `plugin-event-command` command does not support any vars.
+By default this template is automatically imported into all CheckCommand definitions.
+
### <a id="itl-legacy-timeperiod"></a> legacy-timeperiod
Timeperiod template for [Timeperiod objects](9-object-types.md#objecttype-timeperiod).
The `legacy-timeperiod` timeperiod does not support any vars.
+By default this template is automatically imported into all CheckCommand definitions.
+
## <a id="itl-check-commands"></a> Check Commands
These check commands are embedded into Icinga 2 and do not require any external
Parent objects are resolved in the order they're specified using the
`import` keyword.
+Default templates which are automatically imported into all object definitions
+can be specified using the `default` keyword:
+
+ template CheckCommand "plugin-check-command" default {
+ // ...
+ }
+
+Default templates are imported before any other user-specified statement in an
+object definition is evaluated.
+
+If there are multiple default templates the order in which they are imported
+is unspecified.
+
## <a id="constants"></a> Constants
Global constants can be set using the `const` keyword:
While you could manually migrate this like (please note the new generic command arguments and default argument values!):
object CheckCommand "my-ping-check" {
- import "plugin-check-command"
-
command = [
PluginDir + "/check_ping", "-4"
]
Can be written as the following in Icinga 2:
object CheckCommand "test_customvar" {
- import "plugin-check-command"
command = "echo "Host CV: $host.vars.CVTEST$ Service CV: $service.vars.CVTEST$\n""
}
the function and uses whatever value the function returns:
object CheckCommand "random-value" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_dummy", "0", "$text$" ]
vars.text = {{ Math.random() * 100 }}
run against:
object CheckCommand "my-ping" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_ping", "-H", "$ping_address$" ]
arguments = {
#### <a id="command-plugin-integration"></a> Integrate the Plugin with a CheckCommand Definition
-[CheckCommand](9-object-types.md#objecttype-checkcommand) objects require the [ITL template](10-icinga-template-library.md#itl-plugin-check-command)
-`plugin-check-command` to support native plugin based check methods.
-
Unless you have done so already, download your check plugin and put it
into the [PluginDir](4-configuring-icinga-2.md#constants-conf) directory. The following example uses the
`check_mysql` plugin contained in the Monitoring Plugins package.
# vim /etc/icinga2/conf.d/commands.conf
object CheckCommand "my-mysql" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_mysql" ] //constants.conf -> const PluginDir
arguments = {
macro value can be resolved by Icinga 2.
object CheckCommand "check_http" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_http" ]
arguments = {
when passing credentials to database checks:
object CheckCommand "mysql-health" {
- import "plugin-check-command"
-
command = [
PluginDir + "/check_mysql"
]
[NotificationCommand](9-object-types.md#objecttype-notificationcommand) objects are referenced by
[Notification](9-object-types.md#objecttype-notification) objects using the `command` attribute.
-`NotificationCommand` objects require the [ITL template](10-icinga-template-library.md#itl-plugin-notification-command)
-`plugin-notification-command` to support native plugin-based notifications.
-
> **Note**
>
> Make sure that the [notification](11-cli-commands.md#enable-features) feature is enabled
you can add a `vars` dictionary as shown for the `CheckCommand` object.
object NotificationCommand "mail-service-notification" {
- import "plugin-notification-command"
-
command = [ SysconfDir + "/icinga2/scripts/mail-notification.sh" ]
env = {
restart via event command, or if an application is locked and requires
a restart upon detection.
-`EventCommand` objects require the ITL template `plugin-event-command`
-to support native plugin based checks.
-
#### <a id="event-command-restart-service-daemon"></a> Use Event Commands to Restart Service Daemon
The following example will trigger a restart of the `httpd` daemon
/* pass event commands through ssh */
object EventCommand "event_by_ssh" {
- import "plugin-event-command"
-
command = [ PluginDir + "/check_by_ssh" ]
arguments = {
Please make sure to follow these conventions when adding a new command object definition:
-* Always import the `plugin-check-command` template.
* Use [command arguments](3-monitoring-basics.md#command-arguments) whenever possible. The `command` attribute
must be an array in `[ ... ]` for shell escaping.
* Define a unique `prefix` for the command's specific arguments. That way you can safely
This is an example for a custom `my-snmp-int` check command:
object CheckCommand "my-snmp-int" {
- import "plugin-check-command"
-
command = [ CustomPluginDir + "/check_snmp_int.pl" ]
arguments = {
[root@icinga2-master1.localdomain /]# vim /etc/icinga2/zones.d/global-templates/commands.conf
object CheckCommand "my-cmd" {
- import "plugin-check-command"
-
//...
}
[root@icinga2-master1.localdomain /]# vim /etc/icinga2/zones.d/global-templates/commands.conf
object CheckCommand "my-cmd" {
- import "plugin-check-command"
-
//...
}
Add an `EventCommand` configuration object for the passive service auto reset event.
object EventCommand "coldstart-reset-event" {
- import "plugin-event-command"
-
command = [ SysconfDir + "/icinga2/conf.d/custom/scripts/coldstart_reset_event.sh" ]
arguments = {
solved like this:
object CheckCommand "check_compellent" {
- import "plugin-check-command"
command = [ "/usr/bin/check_compellent" ]
arguments = {
"--disks" = {
You can omit the `log()` calls, they only help debugging.
object NotificationCommand "mail-host-notification-test" {
- import "plugin-notification-command"
command = {{
log("command as function")
var mailscript = "mail-host-notification-long.sh"
Example:
object CheckCommand "check_http" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_http" ]
arguments = {
Name |Description
----------------|----------------
- execute |**Required.** The "execute" script method takes care of executing the check. In virtually all cases you should import the "plugin-check-command" template to take care of this setting.
+ execute |**Required.** The "execute" script method takes care of executing the check. The default template "plugin-check-command" which is imported into all CheckCommand objects takes care of this setting.
command |**Required.** The command. This can either be an array of individual command arguments. Alternatively a string can be specified in which case the shell interpreter (usually /bin/sh) takes care of parsing the command. When using the "arguments" attribute this must be an array. Can be specified as function for advanced implementations.
env |**Optional.** A dictionary of macros which should be exported as environment variables prior to executing the command.
vars |**Optional.** A dictionary containing custom attributes that are specific to this command.
Example:
object EventCommand "restart-httpd-event" {
- import "plugin-event-command"
-
command = "/opt/bin/restart-httpd.sh"
}
Name |Description
----------------|----------------
- execute |**Required.** The "execute" script method takes care of executing the event handler. In virtually all cases you should import the "plugin-event-command" template to take care of this setting.
+ execute |**Required.** The "execute" script method takes care of executing the event handler. The default template "plugin-event-command" which is imported into all CheckCommand objects takes care of this setting.
command |**Required.** The command. This can either be an array of individual command arguments. Alternatively a string can be specified in which case the shell interpreter (usually /bin/sh) takes care of parsing the command.
env |**Optional.** A dictionary of macros which should be exported as environment variables prior to executing the command.
vars |**Optional.** A dictionary containing custom attributes that are specific to this command.
Example:
object NotificationCommand "mail-service-notification" {
- import "plugin-notification-command"
-
command = [
SysconfDir + "/icinga2/scripts/mail-notification.sh"
]
Name |Description
----------------|----------------
- execute |**Required.** The "execute" script method takes care of executing the notification. In virtually all cases you should import the "plugin-notification-command" template to take care of this setting.
+ execute |**Required.** The "execute" script method takes care of executing the notification. The default template "plugin-notification-command" which is imported into all CheckCommand objects takes care of this setting.
command |**Required.** The command. This can either be an array of individual command arguments. Alternatively a string can be specified in which case the shell interpreter (usually /bin/sh) takes care of parsing the command.
env |**Optional.** A dictionary of macros which should be exported as environment variables prior to executing the command.
vars |**Optional.** A dictionary containing custom attributes that are specific to this command.
/* Command objects */
object NotificationCommand "mail-host-notification" {
- import "plugin-notification-command"
-
command = [ SysconfDir + "/icinga2/scripts/mail-host-notification.sh" ]
env = {
}
object NotificationCommand "mail-service-notification" {
- import "plugin-notification-command"
-
command = [ SysconfDir + "/icinga2/scripts/mail-service-notification.sh" ]
env = {
}
object CheckCommand "nscp-local" {
- import "plugin-check-command"
-
command = [ NscpPath + "\\nscp.exe", "client" ]
arguments = {
*/
template CheckCommand "snmp-manubulon-command" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
arguments = {
******************************************************************************/
object CheckCommand "disk-windows" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_disk.exe" ]
arguments = {
}
object CheckCommand "load-windows" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_load.exe" ]
arguments = {
}
object CheckCommand "memory-windows" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_memory.exe" ]
arguments = {
}
object CheckCommand "network-windows" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_network.exe" ]
arguments = {
}
object CheckCommand "perfmon-windows" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_perfmon.exe" ]
arguments = {
template CheckCommand "ping-common-windows" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_ping.exe" ]
arguments = {
}
object CheckCommand "procs-windows" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_procs.exe" ]
arguments = {
}
object CheckCommand "service-windows" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_service.exe" ]
arguments = {
}
object CheckCommand "swap-windows" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_swap.exe" ]
arguments = {
}
object CheckCommand "update-windows" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_update.exe" ]
arguments = {
}
object CheckCommand "uptime-windows" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_uptime.exe" ]
arguments = {
}
object CheckCommand "users-windows" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_users.exe" ]
arguments = {
}
template CheckCommand "ping-common" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_ping" ]
arguments = {
}
template CheckCommand "fping-common" {
- import "plugin-check-command"
-
command = [
PluginDir + "/check_fping",
"$fping_address$"
}
object CheckCommand "dummy" {
- import "plugin-check-command"
-
command = [
PluginDir + "/check_dummy",
"$dummy_state$",
}
object CheckCommand "tcp" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_tcp" ]
}
object CheckCommand "ssl" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_tcp" ]
}
object CheckCommand "udp" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [
}
object CheckCommand "http" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_http" ]
}
object CheckCommand "ftp" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_ftp" ]
}
object CheckCommand "smtp" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_smtp" ]
}
object CheckCommand "ssmtp" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_ssmtp" ]
}
object CheckCommand "imap" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_imap" ]
}
object CheckCommand "simap" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_simap" ]
}
object CheckCommand "pop" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_pop" ]
}
object CheckCommand "spop" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_spop" ]
}
object CheckCommand "ntp_time" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_ntp_time" ]
}
object CheckCommand "ntp_peer" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_ntp_peer" ]
}
object CheckCommand "ssh" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_ssh" ]
}
object CheckCommand "disk" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_disk" ]
arguments = {
}
object CheckCommand "disk_smb" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_disk_smb" ]
arguments = {
}
object CheckCommand "users" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_users" ]
arguments = {
}
object CheckCommand "procs" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_procs" ]
arguments = {
}
object CheckCommand "swap" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_swap" ]
arguments = {
}
object CheckCommand "load" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_load" ]
arguments = {
}
object CheckCommand "snmp" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_snmp" ]
arguments = {
}
object CheckCommand "snmpv3" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_snmp" ]
}
object CheckCommand "apt" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_apt" ]
arguments = {
}
object CheckCommand "dhcp" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_dhcp" ]
arguments = {
}
object CheckCommand "dns" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_dns" ]
}
object CheckCommand "dig" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_dig" ]
}
object CheckCommand "nscp" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_nt" ]
}
object CheckCommand "by_ssh" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_by_ssh" ]
}
object CheckCommand "ups" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_ups" ]
}
object CheckCommand "nrpe" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_nrpe" ]
}
object CheckCommand "hpjd" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_hpjd" ]
}
object CheckCommand "icmp" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_icmp" ]
arguments = {
}
object CheckCommand "ldap" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_ldap" ]
}
object CheckCommand "clamd" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_clamd" ]
arguments = {
}
object CheckCommand "mailq" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_mailq" ]
arguments = {
}
object CheckCommand "pgsql" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_pgsql" ]
}
object CheckCommand "mysql" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_mysql" ]
}
object CheckCommand "negate" {
- import "plugin-check-command"
-
command = [ PluginDir + "/negate" ]
arguments = {
}
object CheckCommand "file_age" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_file_age" ]
arguments = {
}
object CheckCommand "smart" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_ide_smart" ]
arguments = {
}
object CheckCommand "breeze" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_breeze" ]
}
object CheckCommand "flexlm" {
- import "plugin-check-command"
-
command = [ PluginDir + "/check_flexlm" ]
arguments = {
}
object CheckCommand "game" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_game" ]
}
object CheckCommand "mysql_query" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginDir + "/check_mysql_query" ]
******************************************************************************/
object CheckCommand "mssql_health" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_mssql_health" ]
arguments = {
}
object CheckCommand "mysql_health" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginContribDir + "/check_mysql_health" ]
}
object CheckCommand "db2_health" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_db2_health" ]
arguments = {
}
object CheckCommand "oracle_health" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_oracle_health" ]
arguments = {
}
object CheckCommand "postgres" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginContribDir + "/check_postgres.pl" ]
}
object CheckCommand "mongodb" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_mongodb.py" ]
arguments = {
}
object CheckCommand "elasticsearch" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_elasticsearch" ]
arguments = {
}
object CheckCommand "redis" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_redis.pl" ]
arguments = {
******************************************************************************/
object CheckCommand "hpasm" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginContribDir + "/check_hpasm" ]
******************************************************************************/
template CheckCommand "icingacli" {
- import "plugin-check-command"
-
command = [ PrefixDir + "/bin/icingacli" ]
}
******************************************************************************/
object CheckCommand "ipmi-sensor" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginContribDir + "/check_ipmi_sensor" ]
******************************************************************************/
object CheckCommand "graphite" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_graphite" ]
arguments = {
******************************************************************************/
object CheckCommand "interfacetable" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_interface_table_v3t" ]
arguments = {
}
object CheckCommand "iftraffic" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginContribDir + "/check_iftraffic.pl"]
}
object CheckCommand "iftraffic64" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginContribDir + "/check_iftraffic64.pl"]
}
object CheckCommand "interfaces" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginContribDir + "/check_interfaces" ]
}
object CheckCommand "nwc_health" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginContribDir + "/check_nwc_health" ]
******************************************************************************/
object CheckCommand "kdc" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginContribDir + "/check_kdc" ]
}
object CheckCommand "rbl" {
- import "plugin-check-command"
import "ipv4-or-ipv6"
command = [ PluginContribDir + "/check_rbl" ]
******************************************************************************/
object CheckCommand "mem" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_mem.pl" ]
arguments = {
}
object CheckCommand "running_kernel" {
- import "plugin-check-command"
-
command = {{
var use_sudo = macro("$running_kernel_use_sudo$")
}
object CheckCommand "yum" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_yum" ]
arguments = {
}
object CheckCommand "iostat" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_iostat" ]
arguments = {
******************************************************************************/
object CheckCommand "esxi_hardware" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_esxi_hardware.py" ]
arguments = {
*/
template CheckCommand "vmware-esx-command" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_vmware_esx" ]
arguments = {
******************************************************************************/
object CheckCommand "webinject" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_webinject" ]
arguments = {
}
object CheckCommand "jmx4perl" {
- import "plugin-check-command"
-
command = [ PluginContribDir + "/check_jmx4perl" ]
arguments = {
keywords.push_back("locals");
keywords.push_back("use");
keywords.push_back("__using");
+ keywords.push_back("default");
keywords.push_back("ignore_on_error");
keywords.push_back("current_filename");
keywords.push_back("current_line");
use return T_USE;
__using return T_USING;
apply return T_APPLY;
+default return T_DEFAULT;
to return T_TO;
where return T_WHERE;
import return T_IMPORT;
%token T_GLOBALS "globals (T_GLOBALS)"
%token T_LOCALS "locals (T_LOCALS)"
%token T_CONST "const (T_CONST)"
+%token T_DEFAULT "default (T_DEFAULT)"
%token T_IGNORE_ON_ERROR "ignore_on_error (T_IGNORE_ON_ERROR)"
%token T_CURRENT_FILENAME "current_filename (T_CURRENT_FILENAME)"
%token T_CURRENT_LINE "current_line (T_CURRENT_LINE)"
%type <expr> apply
%type <expr> optional_rterm
%type <text> target_type_specifier
+%type <boolean> default_specifier
%type <boolean> ignore_specifier
%type <cvlist> use_specifier
%type <cvlist> use_specifier_items
context->m_Assign.push(0);
context->m_Ignore.push(0);
}
- object_declaration identifier optional_rterm use_specifier ignore_specifier
+ object_declaration identifier optional_rterm use_specifier default_specifier ignore_specifier
{
BeginFlowControlBlock(context, FlowControlReturn, false);
}
context->m_ObjectAssign.pop();
bool abstract = $2;
+ bool defaultTmpl = $6;
+
+ if (!abstract && defaultTmpl)
+ BOOST_THROW_EXCEPTION(ScriptError("'default' keyword is invalid for object definitions", DebugInfoRange(@2, @4)));
String type = *$3;
delete $3;
BOOST_THROW_EXCEPTION(ScriptError("object rule 'ignore' is missing 'assign' for type '" + type + "'", DebugInfoRange(@2, @4)));
}
- $$ = new ObjectExpression(abstract, type, $4, filter, context->GetZone(), context->GetPackage(), $5, $6, $8, DebugInfoRange(@2, @6));
+ $$ = new ObjectExpression(abstract, type, $4, filter, context->GetZone(), context->GetPackage(), $5, $6, $7, $9, DebugInfoRange(@2, @7));
}
;
}
;
+default_specifier: /* empty */
+ {
+ $$ = false;
+ }
+ | T_DEFAULT
+ {
+ $$ = true;
+ }
+ ;
+
ignore_specifier: /* empty */
{
$$ = false;
*/
ConfigItem::ConfigItem(const String& type, const String& name,
bool abstract, const boost::shared_ptr<Expression>& exprl,
- const boost::shared_ptr<Expression>& filter, bool ignoreOnError,
+ const boost::shared_ptr<Expression>& filter, bool defaultTmpl, bool ignoreOnError,
const DebugInfo& debuginfo, const Dictionary::Ptr& scope,
const String& zone, const String& package)
: m_Type(type), m_Name(name), m_Abstract(abstract),
- m_Expression(exprl), m_Filter(filter), m_IgnoreOnError(ignoreOnError),
+ m_Expression(exprl), m_Filter(filter),
+ m_DefaultTmpl(defaultTmpl), m_IgnoreOnError(ignoreOnError),
m_DebugInfo(debuginfo), m_Scope(scope), m_Zone(zone),
m_Package(package)
{
return m_Abstract;
}
+bool ConfigItem::IsDefaultTemplate(void) const
+{
+ return m_DefaultTmpl;
+}
+
+bool ConfigItem::IsIgnoreOnError(void) const
+{
+ return m_IgnoreOnError;
+}
+
/**
* Retrieves the debug information for the configuration item.
*
return items;
}
+std::vector<ConfigItem::Ptr> ConfigItem::GetDefaultTemplates(const String& type)
+{
+ std::vector<ConfigItem::Ptr> items;
+
+ boost::mutex::scoped_lock lock(m_Mutex);
+
+ auto it = m_Items.find(type);
+
+ if (it == m_Items.end())
+ return items;
+
+ for (const ItemMap::value_type& kv : it->second)
+ {
+ if (kv.second->IsDefaultTemplate())
+ items.push_back(kv.second);
+ }
+
+ return items;
+}
+
void ConfigItem::RemoveIgnoredItems(const String& allowedConfigPath)
{
boost::mutex::scoped_lock lock(m_Mutex);
ConfigItem(const String& type, const String& name, bool abstract,
const boost::shared_ptr<Expression>& exprl,
const boost::shared_ptr<Expression>& filter,
- bool ignoreOnError, const DebugInfo& debuginfo,
+ bool defaultTmpl, bool ignoreOnError, const DebugInfo& debuginfo,
const Dictionary::Ptr& scope, const String& zone,
const String& package);
String GetType(void) const;
String GetName(void) const;
bool IsAbstract(void) const;
- bool GetIgnoreOnError(void) const;
+ bool IsDefaultTemplate(void) const;
+ bool IsIgnoreOnError(void) const;
std::vector<ConfigItem::Ptr> GetParents(void) const;
static bool RunWithActivationContext(const Function::Ptr& function);
static std::vector<ConfigItem::Ptr> GetItems(const String& type);
+ static std::vector<ConfigItem::Ptr> GetDefaultTemplates(const String& type);
static void RemoveIgnoredItems(const String& allowedConfigPath);
boost::shared_ptr<Expression> m_Expression;
boost::shared_ptr<Expression> m_Filter;
+ bool m_DefaultTmpl;
bool m_IgnoreOnError;
DebugInfo m_DebugInfo; /**< Debug information. */
Dictionary::Ptr m_Scope; /**< variable scope. */
m_Filter = filter;
}
+void ConfigItemBuilder::SetDefaultTemplate(bool defaultTmpl)
+{
+ m_DefaultTmpl = defaultTmpl;
+}
+
void ConfigItemBuilder::SetIgnoreOnError(bool ignoreOnError)
{
m_IgnoreOnError = ignoreOnError;
dexpr->MakeInline();
exprs.push_back(dexpr);
+#ifdef I2_DEBUG
+ if (!m_Abstract) {
+ bool foundDefaultImport = false;
+
+ for (Expression *expr : m_Expressions) {
+ if (dynamic_cast<ImportDefaultTemplatesExpression *>(expr)) {
+ foundDefaultImport = true;
+ break;
+ }
+ }
+
+ ASSERT(foundDefaultImport);
+ }
+#endif /* I2_DEBUG */
+
boost::shared_ptr<DictExpression> exprl = boost::make_shared<DictExpression>(exprs, m_DebugInfo);
exprl->MakeInline();
return new ConfigItem(m_Type, m_Name, m_Abstract, exprl, m_Filter,
- m_IgnoreOnError, m_DebugInfo, m_Scope, m_Zone, m_Package);
+ m_DefaultTmpl, m_IgnoreOnError, m_DebugInfo, m_Scope, m_Zone, m_Package);
}
void SetScope(const Dictionary::Ptr& scope);
void SetZone(const String& zone);
void SetPackage(const String& package);
+ void SetDefaultTemplate(bool defaultTmpl);
void SetIgnoreOnError(bool ignoreOnError);
void AddExpression(Expression *expr);
Dictionary::Ptr m_Scope; /**< variable scope. */
String m_Zone; /**< The zone. */
String m_Package; /**< The package name. */
+ bool m_DefaultTmpl;
bool m_IgnoreOnError; /**< Whether the object should be ignored when an error occurs in one of the expressions. */
};
return Empty;
}
+ExpressionResult ImportDefaultTemplatesExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
+{
+ if (frame.Sandboxed)
+ BOOST_THROW_EXCEPTION(ScriptError("Imports are not allowed in sandbox mode.", m_DebugInfo));
+
+ String type = VMOps::GetField(frame.Self, "type", frame.Sandboxed, m_DebugInfo);
+
+ for (const ConfigItem::Ptr& item : ConfigItem::GetDefaultTemplates(type)) {
+ Dictionary::Ptr scope = item->GetScope();
+
+ if (scope)
+ scope->CopyTo(frame.Locals);
+
+ ExpressionResult result = item->GetExpression()->Evaluate(frame, dhint);
+ CHECK_RESULT(result);
+ }
+
+ return Empty;
+}
+
ExpressionResult FunctionExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
{
return VMOps::NewFunction(frame, m_Name, m_Args, m_ClosedVars, m_Expression);
}
return VMOps::NewObject(frame, m_Abstract, m_Type, name, m_Filter, m_Zone,
- m_Package, m_IgnoreOnError, m_ClosedVars, m_Expression, m_DebugInfo);
+ m_Package, m_DefaultTmpl, m_IgnoreOnError, m_ClosedVars, m_Expression, m_DebugInfo);
}
ExpressionResult ForExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
Expression *m_Name;
};
+class I2_CONFIG_API ImportDefaultTemplatesExpression : public DebuggableExpression
+{
+public:
+ ImportDefaultTemplatesExpression(const DebugInfo& debugInfo = DebugInfo())
+ : DebuggableExpression(debugInfo)
+ { }
+
+protected:
+ virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
+};
+
class I2_CONFIG_API FunctionExpression : public DebuggableExpression
{
public:
public:
ObjectExpression(bool abstract, const String& type, Expression *name, Expression *filter,
const String& zone, const String& package, std::map<String, Expression *> *closedVars,
- bool ignoreOnError, Expression *expression, const DebugInfo& debugInfo = DebugInfo())
+ bool defaultTmpl, bool ignoreOnError, Expression *expression, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Abstract(abstract), m_Type(type),
- m_Name(name), m_Filter(filter), m_Zone(zone), m_Package(package),
+ m_Name(name), m_Filter(filter), m_Zone(zone), m_Package(package), m_DefaultTmpl(defaultTmpl),
m_IgnoreOnError(ignoreOnError), m_ClosedVars(closedVars), m_Expression(expression)
{ }
boost::shared_ptr<Expression> m_Filter;
String m_Zone;
String m_Package;
+ bool m_DefaultTmpl;
bool m_IgnoreOnError;
std::map<String, Expression *> *m_ClosedVars;
boost::shared_ptr<Expression> m_Expression;
}
static inline Value NewObject(ScriptFrame& frame, bool abstract, const String& type, const String& name, const boost::shared_ptr<Expression>& filter,
- const String& zone, const String& package, bool ignoreOnError, std::map<String, Expression *> *closedVars, const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
+ const String& zone, const String& package, bool defaultTmpl, bool ignoreOnError, std::map<String, Expression *> *closedVars, const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
{
ConfigItemBuilder::Ptr item = new ConfigItemBuilder(debugInfo);
item->SetType(type);
item->SetName(name);
+ if (!abstract)
+ item->AddExpression(new ImportDefaultTemplatesExpression());
+
item->AddExpression(new OwnedExpression(expression));
item->SetAbstract(abstract);
item->SetScope(EvaluateClosedVars(frame, closedVars));
item->SetZone(zone);
item->SetPackage(package);
item->SetFilter(filter);
+ item->SetDefaultTemplate(defaultTmpl);
item->SetIgnoreOnError(ignoreOnError);
item->Compile()->Register();
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
-
+
+ builder->AddExpression(new ImportDefaultTemplatesExpression());
+
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
ConfigItem::Ptr dependencyItem = builder->Compile();
System.assert(Internal.run_with_activation_context(function() {
var _Internal = Internal.clone()
- template TimePeriod "legacy-timeperiod" use (_Internal) {
+ template TimePeriod "legacy-timeperiod" use (_Internal) default {
update = _Internal.LegacyTimePeriod
}
}))
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
+ builder->AddExpression(new ImportDefaultTemplatesExpression());
+
ConfigItem::Ptr notificationItem = builder->Compile();
notificationItem->Register();
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
+ builder->AddExpression(new ImportDefaultTemplatesExpression());
+
ConfigItem::Ptr downtimeItem = builder->Compile();
downtimeItem->Register();
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
+ builder->AddExpression(new ImportDefaultTemplatesExpression());
+
ConfigItem::Ptr serviceItem = builder->Compile();
serviceItem->Register();
execute = _Internal.ClusterZoneCheck
}
- template CheckCommand "plugin-check-command" use (_Internal) {
+ template CheckCommand "plugin-check-command" use (_Internal) default {
execute = _Internal.PluginCheck
}
}
}
- template NotificationCommand "plugin-notification-command" use (_Internal) {
+ template NotificationCommand "plugin-notification-command" use (_Internal) default {
execute = _Internal.PluginNotification
}
- template EventCommand "plugin-event-command" use (_Internal) {
+ template EventCommand "plugin-event-command" use (_Internal) default {
execute = _Internal.PluginEvent
}