The NConf application consists of a PHP part and a Perl part. All GUI specific functionality is implemented in PHP. Authentication modules and install/update functionality is also implemented in PHP.
Background functionality such as import and export of Nagios configuration files is implemented in Perl. Any command-line scripts, which use the database API, are also programmed in Perl.
The database is a MySQL DB which uses InnoDB for referential integrity checking.
NConf consists of 15 default classes that roughly represent the configuration objects available in Nagios. Some proprietary classes were introduced to facilitate the handling and to allow inheritance of certain properties.
Each class has multiple attributes. Most of the attributes are Nagios specific. Some proprietary attributes were added to allow additional functionality.
The GUI offers the possibility to add additional attributes and classes, or modify existing ones. This is usually not necessary, since NConf already comes with a schema that covers all necessary Nagios features. Small modifications to the default values of attributes, to their description or their ordering within the GUI might be useful.
As already addressed, the web interface is implemented in PHP. All views and forms are implemented as dynamically as possible, so that no changes to the PHP code are necessary, if Nagios configuration attributes change.
Each HTML form is generated dynamically based on the information in the ConfigAttrs table. This allows us to drastically reduce the amount of code required for general functionality (add/modify/delete). Some exceptions exist for host and service items.
To guarantee maximum flexibility towards future changes to the Nagios software, we chose to implement a very abstract data model (EAV data model) that would allow us to reproduce any objects available within Nagios. You will not find any classic tables in the database such as “host”, “service” etc. Instead, we abstracted each object type to a so called “configuration item”. Each item is linked to a certain “class” and has multiple “attributes” assigned to it. A class roughly represents a Nagios config file. Attribute values are stored separately from attributes, so that attributes only need to be defined once. Items can be linked with each other.
An example query to replace values in the DB
/* Replace a string in all host's "address" attributes */ UPDATE ConfigValues, ConfigAttrs, ConfigClasses SET ConfigValues.attr_value = REPLACE(attr_value,'192.168.1.','10.110.1.') WHERE ConfigValues.fk_id_attr=ConfigAttrs.id_attr AND ConfigAttrs.fk_id_class=ConfigClasses.id_class AND ConfigClasses.config_class="host" AND ConfigAttrs.attr_name="address";
More information regarding configuration attributes:
The “ConfigAttrs” table is the most complex table in the database. It holds the individual configuration items that the Nagios config files consist of. It is also used to influence the appearance of the web interface. Each attribute is linked to a class. The PHP logic of the web interface simply selects all attributes linked to a certain class and generates HTML forms based on the parameters defined in the ConfigAttrs table: Is an attribute visible, how many characters can it hold, does it have a default value, is it mandatory, what is the ordering?
The most important information is the attribute’s “datatype”.
The following types exist:
Other important attribute parameters are the following: