proper-speck
You are here: HomeForum
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: [solved] how to remove values with import

[solved] how to remove values with import 4 years 7 months ago #1420

  • keli
  • keli's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
We recently migrated from nagios 1.4.1 to 3.2 and while we were at it, we also started using NagiosQL 3.0.3 to manage it's configuration.

Since the migration was far from perfect, now I have a lot of cleanup work to do on a large number of hosts.

NagiosQL is a great tool otherwise, but it isn't really good at working with multiple hosts at once (this could be a feature request, by the way), I've written some command line php scripts for myself to augment that. (for example: add/remove template to each member of a hostgroup, or to each host with host_name matching a regular expression etc.)

My scripts spit out a nagios object definitions, so I'm using them together with the import function of NagiosQL.

However, I was surprised to find, that all import seems to be additive, unless I delete the host definitions beforehand:

I wanted to remove max_check_attempts form every host (it's provided by a generic-host template): if I don't add the variable to my definition, it keeps the old value. If I add it with a value of 0, a literal "0" appears, that isn't what I've wanted (empty value); with values -1 and null "null" (with small letters) appears in the form, and the file export/check will give errors (as "null" isn't an accepted value).

I wanted to remove hosttemplates as well (from the "use" variable of a host's definition), but it only seems to add templates to the existing ones, never remove those not included in the imported definition ...

any ideas how can I remove items from such lists, and how to clear out variables I don't want to use?
Last Edit: 4 years 2 months ago by martin.
The topic has been locked.

Re:how to remove values with import 4 years 7 months ago #1422

  • martin
  • martin's Avatar
  • OFFLINE
  • NagiosQL Founder
  • Posts: 1240
  • Thank you received: 95
Have you used the "overwriting option" during your imports? Imports are only additive if you dont' check this.

For max_check_attempts look at the official Nagios documentation (this is a must have parameter! - removing is not allowed):

max_check_attempts: This directive is used to define the number of times that Nagios will retry the host check command if it returns any state other than an OK state. Setting this value to 1 will cause Nagios to generate an alert without retrying the host check. Note: If you do not want to check the status of the host, you must still set this to a minimum value of 1. To bypass the host check, just leave the check_command option blank.
Got help from one of the developers?
Help us with your donation! www.nagiosql.org/donate.html
Last Edit: 4 years 7 months ago by martin.
The topic has been locked.

Re:how to remove values with import 4 years 7 months ago #1423

  • keli
  • keli's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
I have always used the overwriting option, or else it would complain that the given host already exists in the database, and would not allow the import for that host at all. Even when overwriting, some values only seem to be added instead of "overwritten" (see my original post on templates for example)

Regarding max_check_attempts: I know it's a required parameter, but it would have been covered by a template.

I have generic-host with max_check_attempts set to three, and various hosts with various values for max_check_attempts. I wanted to reset all the values by removing the variable from the host definition, to let it fall back to the template's definition.

If I don't remove the variable (if I use 1 or 0 or something like that) an existing value in the host's definition will always override a template's definition.
The topic has been locked.

Re:how to remove values with import 4 years 7 months ago #1424

  • martin
  • martin's Avatar
  • OFFLINE
  • NagiosQL Founder
  • Posts: 1240
  • Thank you received: 95
Yes. the host definition is always "at the top" of your configuration tree - it is not possible to remove any value of a single definition be adding a template. The host definition settings will always overwrite any template settings.

You can remove a value like "max_check_attemps" in NagiosQL's form by simple delete this field (no 0, no 1, no 'null' - only an empty field).

A selective import is not possible - but - because all data is stored inside a database, you can manipulate them faster with an SQL editor like phpMyAdmin or something else.

Removing the max_check_attemts from any hosts of your tbl_host can be done with a:

UPDATE `tbl_host` SET `max_check_attempts` = NULL
Got help from one of the developers?
Help us with your donation! www.nagiosql.org/donate.html
The topic has been locked.

Re:how to remove values with import 4 years 7 months ago #1425

  • keli
  • keli's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
I ended up doing just that myself, I was just wondering whether it could have been done at import.

You could have NagiosQL clear those values when the import process sees a 0 (or -1, or null or whatever), as currently it erroneously inserts a "null" string instead of a NULL value, when using one of the latter two.

If the user creates an invalid configuration through importing (by example when omitting/removing a required variable, and not filling it with a template) that is just as much not the error of NagiosQL, as it were if s/he would create one while filling out the web form. That is why there's a configuration check available.

Here's my suggestion/request:
  • allow a "complete overwrite" import: in the case of a matching an existing object name this would be equivalent to deleting the object to be overwritten with all data associated through that single object definition (for example associations with templates, variables etc.), but not inversely (like group memberships of that object, that are defined outside the object definition) and then re-insert the object definition from the imported data.
  • and/or: allow methods of removing existing variables or list members, by a defined method. For example:
    • setting "-1" or "null" as a value to clear a variable
    • adding a list member with a "-" prefix to remove it from that list:
      example:
      original host object:
      use generic-host,template-green,template-red

      imported host object
      use -template-green

      resulting host object
      use generic-host,template-red

If you're interested, I could look into implementing these changes (if they're not implemented yet and I have overlooked something)
The topic has been locked.

Re:how to remove values with import 4 years 7 months ago #1426

  • martin
  • martin's Avatar
  • OFFLINE
  • NagiosQL Founder
  • Posts: 1240
  • Thank you received: 95
keli wrote:
Here's my suggestion/request:
  • allow a "complete overwrite" import: in the case of a matching an existing object name this would be equivalent to deleting the object to be overwritten with all data associated through that single object definition (for example associations with templates, variables etc.), but not inversely (like group memberships of that object, that are defined outside the object definition) and then re-insert the object definition from the imported data.
Setting the "overwrite" flag should be such a "complete overwrite" - if not - this is a bug. But I have never seen that this is not proper working up to now...
  • and/or: allow methods of removing existing variables or list members, by a defined method. For example:
    • setting "-1" or "null" as a value to clear a variable
    • adding a list member with a "-" prefix to remove it from that list:
  • This is actually implemented - just delete the complete config line - not only the value - if the config parameter is not found by the importer - it will be set to the default (empty) value. So you can simple remove the max_check_attempts line from your host configurations before import them.
    Got help from one of the developers?
    Help us with your donation! www.nagiosql.org/donate.html
    Last Edit: 4 years 7 months ago by martin.
    The topic has been locked.
    • Page:
    • 1
    • 2
    Time to create page: 0.359 seconds

    Mailbox

    You are not logged in.

    Go to top proper-speck