Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev.icinga.com #12917] Duplicate groups allowed when creating host #4732

Closed
icinga-migration opened this issue Oct 13, 2016 · 3 comments · Fixed by #6294
Closed

[dev.icinga.com #12917] Duplicate groups allowed when creating host #4732

icinga-migration opened this issue Oct 13, 2016 · 3 comments · Fixed by #6294
Labels
area/api REST API area/configuration DSL, parser, compiler, error handling bug Something isn't working
Milestone

Comments

@icinga-migration
Copy link

This issue has been migrated from Redmine: https://dev.icinga.com/issues/12917

Created by xert on 2016-10-13 12:25:12 +00:00

Assignee: (none)
Status: New
Target Version: (none)
Last Update: 2016-10-13 12:25:12 +00:00 (in Redmine)

Icinga Version: v2.5.4-127-gc81b4a8
Backport?: Not yet backported
Include in Changelog: 1

Given this JSON when creating host:

{
        "attrs": {

        "check_command": "hostalive",
        "groups": [
          "all-hosts",
          "linux-servers",
          "linux-servers"
        ]    
      }
}

then this host is created:

{
  "results": [
    {
      "attrs": {
        ...
        "check_command": "hostalive",
        "groups": [
          "all-hosts",
           "linux-servers",
          "linux-servers",
          "all-hosts"
        ],
       ...
    }
  ]
}

There are two problems:

  1. linux-servers group is allowed to be added twice
  2. all-hosts group is appended to the group list even if it's already in the request
@icinga-migration icinga-migration added bug Something isn't working area/api REST API labels Jan 17, 2017
@gunnarbeutner gunnarbeutner added area/configuration DSL, parser, compiler, error handling and removed area/api REST API labels Feb 7, 2017
@dnsmichi dnsmichi added the area/api REST API label Jun 9, 2017
@dnsmichi
Copy link
Contributor

dnsmichi commented May 9, 2018

Requires two fixes:

  • lib/icinga/*group.cpp where groups->Add() happens
  • Expose Unique() and do sanity checks on the user input

Array::Unique() needs unit tests

Tests

$ curl -k -s -u root:icinga -X PUT -H 'Accept: application/json' 'https://localhost:5665/v1/objects/hosts/h1' -d '{ "attrs": { "check_command": "hostalive", "groups" : [ "linux-servers", "linux-servers" ] } }'

There's an assign rule which adds linux-servers and linux-servers-2 in the background via static configuration.

object HostGroup "linux-servers" {
  assign where host.vars.os == "Linux"
  assign where true
}
object HostGroup "linux-servers-2" {
  assign where host.vars.os == "Linux"
  assign where true
}

@dnsmichi
Copy link
Contributor

dnsmichi commented May 9, 2018

Now, that's the correct output. Previous had a patch stashed.

michi@mbmif ~/coding/icinga/icinga2 (feature/unique-groups-api) $ curl -k -s -u root:icinga -X PUT -H 'Accept: application/json' 'https://localhost:5665/v1/objects/hosts/h1' -d '{ "attrs": { "check_command": "hostalive", "groups" : [ "linux-servers", "linux-servers" ] } }'
michi@mbmif ~/coding/icinga/icinga2 (feature/unique-groups-api) $ mif ~/coding/icinga/icinga2 (GET 'https://localhost:5665/v1/objects/hosts/h1?pretty=1'
{
    "results": [
        {
            "attrs": {
                "__name": "h1",
                "acknowledgement": 0.0,
                "acknowledgement_expiry": 0.0,
                "action_url": "",
                "active": true,
                "address": "",
                "address6": "",
                "check_attempt": 1.0,
                "check_command": "hostalive",
                "check_interval": 300.0,
                "check_period": "",
                "check_timeout": null,
                "command_endpoint": "",
                "display_name": "h1",
                "downtime_depth": 0.0,
                "enable_active_checks": true,
                "enable_event_handler": true,
                "enable_flapping": false,
                "enable_notifications": true,
                "enable_passive_checks": true,
                "enable_perfdata": true,
                "event_command": "",
                "flapping": false,
                "flapping_current": 0.0,
                "flapping_last_change": 0.0,
                "flapping_threshold": 0.0,
                "flapping_threshold_high": 30.0,
                "flapping_threshold_low": 25.0,
                "force_next_check": false,
                "force_next_notification": false,
                "groups": [
                    "linux-servers",
                    "linux-servers-2"
                ],
                "ha_mode": 0.0,
                "icon_image": "",
                "icon_image_alt": "",
                "last_check": -1.0,
                "last_check_result": null,
                "last_hard_state": 1.0,
                "last_hard_state_change": 1525879431.2772829533,
                "last_reachable": true,
                "last_state": 1.0,
                "last_state_change": 1525879431.2772829533,
                "last_state_down": 0.0,
                "last_state_type": 0.0,
                "last_state_unreachable": 0.0,
                "last_state_up": 0.0,
                "max_check_attempts": 3.0,
                "name": "h1",
                "next_check": 1525879516.6672263145,
                "notes": "",
                "notes_url": "",
                "original_attributes": null,
                "package": "_api",
                "paused": false,
                "retry_interval": 60.0,
                "severity": 24.0,
                "source_location": {
                    "first_column": 0.0,
                    "first_line": 1.0,
                    "last_column": 15.0,
                    "last_line": 1.0,
                    "path": "/usr/local/icinga2/var/lib/icinga2/api/packages/_api/6eeb02b0-705c-4b46-ad16-8f02b65cce56/conf.d/hosts/h1.conf"
                },
                "state": 1.0,
                "state_type": 0.0,
                "templates": [
                    "h1"
                ],
                "type": "Host",
                "vars": null,
                "version": 1525879467.1726520061,
                "volatile": false,
                "zone": "master"
            },
            "joins": {

            },
            "meta": {

            },
            "name": "h1",
            "type": "Host"
        }
    ]
}

@dnsmichi
Copy link
Contributor

dnsmichi commented May 9, 2018

console still works, only the underlaying code needed changes.

michi@mbmif ~/coding/icinga/icinga2 (feature/unique-groups-api) $ icinga2 console
Icinga 2 (version: v2.8.4-694-g2db5ba2e1)
Type $help to view available commands.
<1> => [ "1", "2", "1" ].unique()
[ "1", "2" ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api REST API area/configuration DSL, parser, compiler, error handling bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants