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

Unable to define handler specific config properly #647

Closed
rgeniesse opened this issue Apr 28, 2017 · 12 comments
Closed

Unable to define handler specific config properly #647

rgeniesse opened this issue Apr 28, 2017 · 12 comments
Assignees
Labels

Comments

@rgeniesse
Copy link

rgeniesse commented Apr 28, 2017

Description of problem

  • What did you do?
    Attempted to use the config hash in handler.pp.

  • What happened?
    The module repeats the name of the handler instead of adding the custom config to the current one. Example:

{
  "handlers": {
    "graphite_nagios": {
      "command": null,
      "type": "tcp",
      "socket": {
        "host": "localhost",
        "port": 2003
      },
      "mutator": "nagios_perfdata",
      "filters": [

      ],
      "severities": [
        "ok",
        "warning",
        "critical",
        "unknown"
      ]
    }
  }
}

Becomes

{
  "handlers": {
    "graphite_nagios": {
      "command": null,
      "type": "tcp",
      "socket": {
        "host": "localhost",
        "port": 2003
      },
      "handle_silenced": true,
      "filters": [

      ],
      "severities": [
        "ok",
        "warning",
        "critical",
        "unknown"
      ]
    }
  },
  "graphite_nagios": {
    "handle_silenced": true
  }
}
  • What did you expect to happen?
    I expected the code to turn out like this, order doesn't matter, just under the same handle scope:
{
  "handlers": {
    "graphite_nagios": {
      "command": null,
      "type": "tcp",
      "socket": {
        "host": "localhost",
        "port": 2003
      },
      "mutator": "nagios_perfdata",
      "handle_silenced": true,
      "filters": [

      ],
      "severities": [
        "ok",
        "warning",
        "critical",
        "unknown"
      ]
    }
  }
}
  • How can someone reproduce the problem?

I reproduced it both inside the manifest and through hiera. Hiera code:

sensu::handlers:
  'graphite_nagios':
    type: 'tcp'
    socket:
      host: 'localhost'
      port: '2003'
    mutator: 'nagios_perfdata'
    config:
      handle_silenced: true

Puppet code:

  sensu::handler { 'graphite_nagios':
    type      => 'tcp',
    socket   => {host => 'localhost', port => '2003'},
    mutator => 'nagios_perfdata',
    config    => { handle_silenced => true},
  }

Command used and debugging output

  • What does your puppet config look like (including any hiera config)
    See above
  • Is this a masterless or master based puppet setup?
    master based

Platform and version information

  • Your OS: CentOS 7 on agent. CentOS 6 on Master
  • Your Ruby version: ruby 1.8.7
  • Your version of Puppet: Puppet Enterprise 2016.4.0 (4.7.0)
  • Your version of Sensu: 0.28.4
  • Your version of this module: v2.2.0

Anything else to add that you think will be helpful?

@rgeniesse
Copy link
Author

write_json should solve this. If it doesn't, I'll make a new issue.

@johannagnarsson
Copy link

Ran into this while trying to add a filter to my handler, if write_json solves this then why have the sensu::handler feature? I would like to propose that this bug at least be reopened.

@rgeniesse rgeniesse reopened this Oct 26, 2018
@rgeniesse
Copy link
Author

@johannagnarsson, could you add steps to reproduce this issue, along with Platform and version information as shown at the bottom of the issue? The way this issue is described may longer be valid as handle_silenced is a native type now and when I opened the issue it was custom:

4d3b853

As filters is also a native type, we'll need to know the steps to reproduce. Thanks!

@ghoneycutt
Copy link
Collaborator

@johannagnarsson please use the latest version of this module and let us know how it goes as @rgeniesse suggested. We're looking forward to your response and happy to help get this resolved.

@johannagnarsson
Copy link

johannagnarsson commented Oct 26, 2018

Hello @rgeniesse, @ghoneycutt thank you for your responses.

Command used and debugging output
What does your puppet config look like (including any hiera config)
See below, no hiera.

Is this a masterless or master based puppet setup?
master based

Platform and version information
Your OS: CentOS 7.5.1804.
Your Ruby version: 2.4.4p296 (Sensu Embedded)
Your version of Puppet: 4.10.12 / Puppetserver 2.8.1
Your version of Sensu: 1.6.1-1.el7.x86_64
Your version of this module: v2.55.1

Latest version of sensu puppet module:

$ puppet module upgrade --modulepath /src/git/bfd/puppet sensu-sensu
Notice: Preparing to upgrade 'sensu-sensu' ...
Notice: Found 'sensu-sensu' (v2.55.1) in /src/git/bfd/puppet ...
Notice: Downloading from https://forgeapi.puppet.com ...
Notice: Could not upgrade module 'sensu-sensu' (v2.55.1 -> latest)
  The installed version is already the latest version matching v2.55.1 -> latest
    Use `puppet module upgrade --force` to upgrade only this module

Here is the puppet snippet of the handler definition:

# Logstash handler
  sensu::handler { 'logstash':
    type   => 'tcp',
    socket => {
        'host' => $monitoring::logstash_host,
        'port' => $monitoring::logstash_port
    },
    config => {
      'filters' => [ 'state_change_only' ],
    }
  } 

And this is the config file that was written out (/etc/sensu/conf.d/handlers/logstash.json):

{
  "handlers": {
    "logstash": {
      "command": null,
      "type": "tcp",
      "socket": {
        "host": "<redacted>",
        "port": <redacted>
      },
      "filters": [

      ],
      "severities": [
        "ok",
        "warning",
        "critical",
        "unknown"
      ],
      "handle_flapping": false,
      "handle_silenced": false
    }
  },
  "logstash": {
    "filters": [
      "state_change_only"
    ]
  }
}

Filter definition:

sensu::filter {'state_change_only':
    negate     => false,
    attributes => {
      'occurrences' => "eval: value == 1 || ':::action:::' == 'resolve'"
    }
  }

I have another handler defined as well:

  sensu::handler {'webex':
      type    => 'pipe',
      command => '/opt/sensu/embedded/bin/handler-webex.py',
      config  => {
        'filters' => [ 'state_change_only' ],
      }
  }

File written out (/etc/sensu/conf.d/handlers/webex.json):

{
  "handlers": {
    "webex": {
      "command": "/opt/sensu/embedded/bin/handler-webex.py",
      "type": "pipe",
      "filters": [

      ],
      "severities": [
        "ok",
        "warning",
        "critical",
        "unknown"
      ],
      "handle_flapping": false,
      "handle_silenced": false
    }
  },
  "webex": {
    "filters": [
      "state_change_only"
    ]
  }
}

Please let me know if there's any additional information I could provide! Also, I can open a new ticket if that would be more helpful!

@ghoneycutt
Copy link
Collaborator

@johannagnarsson what outputs were you expecting?

@johannagnarsson
Copy link

johannagnarsson commented Oct 26, 2018

This is a correct handler, created by write_json:
Logstash:

{
    "handlers": {
        "logstash": {
            "filters": [
                "state_change_only"
            ],
            "handle_flapping": false,
            "handle_silenced": false,
            "severities": [
                "ok",
                "warning",
                "critical",
                "unknown"
            ],
            "socket": {
                "host": "<redacted>",
                "port": <redacted>
            },
            "type": "tcp"
        }
    }
}

Webex:

{
    "handlers": {
        "webex": {
            "command": "/opt/sensu/embedded/bin/handler-webex.py",
            "filters": [
                "state_change_only"
            ],
            "handle_flapping": false,
            "handle_silenced": false,
            "severities": [
                "ok",
                "warning",
                "critical",
                "unknown"
            ],
            "type": "pipe"
        }
    }
}

Note how the filters isn't empty under "handlers": { "logstash": { "filters": [ ] } } and how there isn't a separate "logstash": { "filters": [] } } definition.

@ghoneycutt
Copy link
Collaborator

The above shows logstash while the previous example used webex. Could you please show the expectation for webex? This allows us to make a diff and debug the issue.

@johannagnarsson
Copy link

johannagnarsson commented Oct 26, 2018

Sorry , I included both in the first comment, I'll add webex to the previous comment as well

@treydock
Copy link
Collaborator

@johannagnarsson Try using filters parameter instead of config. The config parameter looks to be intended to define a custom hash separate from other parameters.

include ::sensu
sensu::handler { 'logstash':
  type   => 'tcp',
  socket => {
      'host' => 'localhost',
      'port' => '8000',
  },
  filters => [ 'state_change_only' ],
}
sensu::handler {'webex':
    type    => 'pipe',
    command => '/opt/sensu/embedded/bin/handler-webex.py',
    filters => [ 'state_change_only' ],
}
{
  "handlers": {
    "logstash": {
      "command": null,
      "type": "tcp",
      "socket": {
        "host": "localhost",
        "port": 8000
      },
      "filters": [
        "state_change_only"
      ],
      "severities": [
        "ok",
        "warning",
        "critical",
        "unknown"
      ],
      "handle_flapping": false,
      "handle_silenced": false
    }
  }
}
{
  "handlers": {
    "webex": {
      "command": "/opt/sensu/embedded/bin/handler-webex.py",
      "type": "pipe",
      "filters": [
        "state_change_only"
      ],
      "severities": [
        "ok",
        "warning",
        "critical",
        "unknown"
      ],
      "handle_flapping": false,
      "handle_silenced": false
    }
  }
}

@ghoneycutt
Copy link
Collaborator

Thanks @treydock !

@johannagnarsson let us know how this goes.

@ghoneycutt
Copy link
Collaborator

Closing due to inactivity. Please re-open if this is still an issue and @treydock 's comments did not solve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants