Skip to content

@Include

Remie Bolte edited this page Jun 26, 2018 · 3 revisions

@Include(ref: NagiosObj|InheritableNagiosObj)

The include decorator tells the command-line interface that it should also compile the class object that was passed in the ref parameter. This is particularity useful for instances of TimeperiodObj where the object is not referenced in the class instance but in the decorator object definition instead.

Parameters

ref: NagiosObj|InheritableNagiosObj an instance of an object which implements NagiosObj or InheritableNagiosObj interfaces.

Example

If we have a '24x7' time period, we might want to refer to it in the decorator:

@Host({
  host_name: 'localhost',
  address: '127.0.0.1',
  check_interval: 5,
  retry_interval: 1,
  max_check_attempts: 5,
  check_period: '24x7',
  process_perf_data: false,
  retain_nonstatus_information: false,
  notification_interval: 0,
  notification_period: '24x7',
  notification_options: 'd,u,r'
})
export class Localhost extends HostObj {}

If we are to omit the @Include decorator on th host, Nagios will not be able to resolve the check_period: '24x7' time period reference because the time period object definition will not exist. We can resolve this with the @Include decorator:

@Host({
  host_name: 'localhost',
  address: '127.0.0.1',
  check_interval: 5,
  retry_interval: 1,
  max_check_attempts: 5,
  check_period: '24x7',
  process_perf_data: false,
  retain_nonstatus_information: false,
  notification_interval: 0,
  notification_period: '24x7',
  notification_options: 'd,u,r'
})
@Include(DefaultTimeperiod)
export class Localhost extends HostObj {}

It is important to note that the ref attribute only excepts class instances, not types. The DefaultTimeperiod reference mentioned in the example is actually the default export of a TimeperiodObj instance, defined as export default const DefaultTimeperiod = new DefaultTimeperiod();. Check out the DefaultTimeperiod class for the full example.

Clone this wiki locally