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

sensu-agent does not parse SENSU_SUBSCRIPTIONS environment variable correctly #3287

Closed
johannagnarsson opened this issue Sep 19, 2019 · 2 comments
Labels
bug component:agent Sensu Agent improvements

Comments

@johannagnarsson
Copy link

Expected Behavior

when setting environment variable SENSU_SUBSCRIPTIONS I would expect it to behave the same way as the --subscriptions parameter.

Current Behavior

When setting the SENSU_SUBSCRIPTIONS environment variable to: linux,foo,bar it results in subscriptions on the client side that look like this:

subscriptions:
- linux,foo,bar
- entity:<hostname>

when starting the agent via sensu-agent start --subscriptions linux,foo,bar it results in subscriptions that look like this:

subscriptions:
- linux
- foo
- bar
- entity: <hostname>

Possible Solution

Ideally the SENSU_SUBSCRIPTIONS environment variable would be parsed in the same way as the --subscriptions command line argument.

Steps to Reproduce (for bugs)

  1. Remove the subscriptions portion from agent.yml
# cat /etc/sensu/agent.yml
---
backend-url:
- wss://backend.domain.com:8081
trusted-ca-file: "/etc/sensu/ssl/ca.crt"
  1. set SENSU_SUBSCRIPTIONS to a comma separated value; "linux,foo,bar"
# cat /etc/systemd/system/sensu-agent.service.d/override.conf 
[Service]
PermissionsStartOnly=true
ExecStartPre=/usr/bin/bash -c "/usr/bin/systemctl set-environment SENSU_SUBSCRIPTIONS=linux,foo,bar"
  1. start sensu-agent
  2. verify subscriptions with sensuctl entity info <hostname>
sensuctl entity info <hostname>
=== <hostname>
Name:                   <hostname>
Entity Class:           agent
Subscriptions:          linux,foo,bar entity:<hostname>
Last Seen:              2019-09-19 10:51:50 -0700 PDT
Hostname:               <hostname>
OS:                     linux
Platform:               centos
Platform Family:        rhel
Platform Version:       7.6.1810

Context

We have a dynamic environment that requires us to set certain configuration values based on runtime data from the host. This prevents us from correctly setting subscriptions

Your Environment

  • Sensu version used (sensuctl, sensu-backend, and/or sensu-agent):
    sensu-{agent,ctl,backend} 5.13
  • Installation method (packages, binaries, docker etc.):
    sensu signed RPM packages.
  • Operating System and version (e.g. Ubuntu 14.04):
    CentOS 7.6.1810
@echlebek echlebek added the bug label Sep 24, 2019
@palourde
Copy link
Contributor

@johannagnarsson This is due to the way Viper, the library we rely on to parse configs, deals with values from environment variables and flags in an inconsistent manner.

I'm not totally sure how we could implement a workaround on our side but in the meantime, you can always do the following instead:

SENSU_SUBSCRIPTIONS="linux macos" sensu-agent

@calebhailey calebhailey added the component:agent Sensu Agent improvements label May 18, 2020
@echlebek
Copy link
Contributor

echlebek commented Mar 9, 2021

I'm going to close this, as this appears to be inherent in the way our CLI framework works, and not something we can directly address without forking or replacing it.

@echlebek echlebek closed this as completed Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug component:agent Sensu Agent improvements
Projects
None yet
Development

No branches or pull requests

4 participants