Skip to content
Remie Bolte edited this page Jun 26, 2018 · 1 revision

@Use(parent: NagiosObj|InheritableNagiosObj, configuration: ObjectDefinition = {})

The use decorator tells the command-line interface that it should create an object inheritance between the annotated class object and the the class object that was passed in the parent parameter.

Object inheritance is an important part of Nagios object configuration because it will allow you to set baseline template and prevent yourself from duplicating a lot of default properties.

You can still add properties to the object using the configuration parameter of the decorator. This is set to ObjectDefinition interface, which is the base interface of all Nagios object definitions. As such, it would also be possible to recast this to @Use(parent: NagiosObj|InheritableNagiosObj, configuration: Host) if you wish to annotate a Host object and still benefit from auto complete.

If you wish to achieve object inheritance, you can also rely on the Javascript class extension (class X extends Y). The difference between class extension and the @Use decorator is that the former will copy the properties from the parent class. With Nagios templates, a separate template object is created. The outcome will be the same so it is mostly personal preference as to which method you use in your project.

The @Use decorator also doubles as an @Include decorator, meaning that the parent class will automatically also be processed by the compiler. There is no need to add a separate @Include decorator!

For more information on how Nagios object inheritance works, please refer to the official documentation.

Parameters

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

configuration: ObjectDefinition = {} a JSON object which extends a valid Nagios object configuration interface (optional)

Example

For most services a lot of the properties are shared between each service. As such, it is recommended to create a generic service template which is used by other services:

@Service({
  name: 'generic-service',
  service_description: 'Generic Service',
  active_checks_enabled: true,
  passive_checks_enabled: true,
  obsess_over_service: true,
  check_freshness: false,
  notifications_enabled: true,
  ... etc, etc
})
export class BaseService extends ServiceObj {}

Now if we create a service, we can inherit from BaseService by using the @Use decorator:

@Use(BaseService)
export class Service extends ServiceObj {}

This will make sure that the Service class inherits all properties set by the @Service decorator on BaseService.