Skip to content

Object definitions

Remie Bolte edited this page Jul 7, 2018 · 2 revisions

To recreate Nagios object definitions in Typescript, a combination of decorators, classes and interfaces are used. There is a combination of those three for each object definition type (e.g. @Host, HostObj and Host.

About decorators

Decorators are an experimental feature of TypeScript (as per the docs). The following list of decorates are all used to annotate a Class object. They will instruct the compiler that it is an Nagios object definition which should be processed.

In addition, you can pass a JSON object to the constructor with the object definition properties that are listed in the Nagios documentation. Interfaces with all available object definition fields are used for code completion in TypeScript enabled IDE's.

A good example of a class annotator is:

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

Here you will see many host object definition fields set to the class by the JSON object passed to the decorator. For more examples of decorators, check out the example project src folder.

Class decorators

@Nagios

@Contact

@Contactgroup

@Host

@HostGroup

@Service

@ServiceGroup

@Include

@Use

Interfaces

The project includes TypeScript interfaces for the main Nagios configuration file, the CGI configuration file and for each of the Nagios object definitions.

The interfaces themselves are not exposed by the package but are used in the decorators and class objects. If you want to see which properties are defined, you can look the the most recent version of the interfaces here:

As Nagios is under active development, these properties can change. This project might not always be up-to-date with all properties available to the different versions of Nagios. As such, the interfaces are mostly used for guidance and IDE auto complete.

If you wish to include Nagios configuration properties that are not defined in the interfaces you can do so be adding them to the configuration parameter in the decorator or as property on the class. Even better, you can create a pull request to make sure this project is up-to-date with Nagios documentation.