sensu/sensu-puppet

Repo does not work on Ubuntu 22.04 ( Jammy )

icalvete opened this issue · 10 comments

During apply the module I got...

Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns:   404  Not Found [IP: 54.241.158.60 443]
Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns: Get:6 https://packagecloud.io/sensu/stable/ubuntu jammy InRelease [24.5 kB]
Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns: Get:9 https://packagecloud.io/sensu/stable/ubuntu jammy/main amd64 Packages [3946 B]
Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns: Reading package lists...
Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns: E: The repository 'https://packagecloud.io/sensu/community/ubuntu jammy Release' does not have a Release file.
Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns: W: https://packagecloud.io/sensu/stable/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
Error: /Stage[main]/Apt::Update/Exec[apt_update]: Failed to call refresh: '/usr/bin/apt-get update' returned 100 instead of one of [0]
Error: /Stage[main]/Apt::Update/Exec[apt_update]: '/usr/bin/apt-get update' returned 100 instead of one of [0]

After apply the module y have this...

root@admin:/etc/apt/sources.list.d# ls -la
total 20
drwxr-xr-x 2 root root 4096 Oct 13 06:31 .
drwxr-xr-x 8 root root 4096 Oct 13 06:31 ..
-rw-r--r-- 1 root root   72 Sep 15 21:52 puppet7.list
-rw-r--r-- 1 root root  179 Oct 13 06:30 sensu.list
-rw-r--r-- 1 root root  195 Oct 13 06:31 sensu_community.list
root@admin:/etc/apt/sources.list.d# cat sensu*
# This file is managed by Puppet. DO NOT EDIT.
# sensu
deb https://packagecloud.io/sensu/stable/ubuntu/ jammy main
deb-src https://packagecloud.io/sensu/stable/ubuntu/ jammy main
# This file is managed by Puppet. DO NOT EDIT.
# sensu_community
deb https://packagecloud.io/sensu/community/ubuntu/ jammy main
deb-src https://packagecloud.io/sensu/community/ubuntu/ jammy main

If I run an apt-get update manually, I got...

Err:8 https://packagecloud.io/sensu/community/ubuntu jammy Release
  404  Not Found [IP: 54.219.218.99 443]
Hit:6 https://packagecloud.io/sensu/stable/ubuntu jammy InRelease
Reading package lists... Done
E: The repository 'https://packagecloud.io/sensu/community/ubuntu jammy Release' does not have a Release file.

packagecloud.io support told me that...

Hi there, thanks for your patience.
The reason why you're getting this error for the Jammy/community repo is because there are zero packages in that repo.

I'm using the module in a Ubuntu 22.04 ( Jammy ) with puppet 7.19.0

root@cthulhu:/etc/puppetlabs/code/environments/production/modules/sensu# git remote -v
origin	https://github.com/sensu/sensu-puppet.git (fetch)
origin	https://github.com/sensu/sensu-puppet.git (push)
root@cthulhu:/etc/puppetlabs/code/environments/production/modules/sensu# git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
root@cthulhu:/etc/puppetlabs/code/environments/production/modules/sensu# git log
commit 9f6abced35b46425d90d6e11902b3607944b72a9 (HEAD -> master, origin/master, origin/HEAD)
Merge: 1e1efcc2 1ea09e78
Author: Garrett Honeycutt <code@garretthoneycutt.com>
Date:   Thu Dec 2 17:50:13 2021 -0500

@icalvete did packagecloud.io's support say when they would be supporting jammy? Is this because they don't currently support that Ubuntu release yet?

@ddelnano They only said ...

Hi there, thanks for your patience.
The reason why you're getting this error for the Jammy/community repo is because there are zero packages in that repo.

I'd recommend opening issues with Sensu Go project as it would seem they don't build packages for Ubuntu 22.04.

I'd recommend opening issues with Sensu Go project as it would seem they don't build packages for Ubuntu 22.04.

Done

sensu/sensu-go#4914

@treydock does the puppet module have that repo as a dependency? The use case for that repo is that it provides an installable package for the sensu-plugin command that's used to install Sensu plugins that haven't been converted to assets. If the reason for including the repo is to have that command, my suggestion would be to remove the dependency altogether. If folks need to have a plugin converted to an asset, then asking on https://github.com/sensu/catalog would be a better avenue than installing the plugins through the sensu-plugin command.

The community repo is only included if you include the sensu::plugins class which is not part of the main sensu::agent setup, so it's opt-in for those wanting to install those non-asset Sensu plugins. The current package installed in sensu::plugins class is the sensu-plugins-ruby package which I think is why the community repo is added if that class is included in the catalog.

Hi @treydock and @asachs01

This is my code.

AGENT

    class { 'sensu':
      api_host                                   => 'sensu3.mydomain.com',
      password                                  => '****',
      agent_password                       => '****',
      agent_entity_config_password => '****',
      ssl_ca_source => 'puppet:///modules/common/ssl/my-ca.crt',
    }
    class { 'sensu::plugins':
      plugins => [
        'cpu-checks',
        'memory-checks',
        'disk-checks',
      ],
    }
    class { 'sensu::agent':
      subscriptions => ['linux', 'nuc']
    }
    sensu::agent::config_entry { 'deregister': value => true }
    sensu::agent::config_entry { 'deregistration-handler': value => 'deregistration' }sensu::agent::config_entry { 'deregialue => 'deregistration' }

BACKEND

    class { 'sensu::backend':
      ssl_cert_source => 'puppet:///modules/common/ssl/my.crt',
      ssl_key_source  => 'puppet:///modules/common/ssl/my.key',
      config_hash     => {
        'deregistration-handler' => 'deregistration',
        'event-log-file'         => '/var/log/sensu/events.log'
      }
    }

  sensu_check { 'check-cpu':
      ensure         => 'absent',
      command        => '/opt/sensu-plugins-ruby/embedded/bin/check-cpu.rb -w 75 -c 85',
      interval       => 60, 
      subscriptions  => 'linux',
      publish        => true,
      runtime_assets => ['sensu-plugins-cpu-checks','sensu-ruby-runtime']
    }

    sensu_check { 'check-mem':
      ensure         => 'absent',
      command        => '/opt/sensu-plugins-ruby/embedded/bin/check-memory-percent.rb',
      interval       => 60,
      subscriptions  => 'linux',
      publish        => true,
      runtime_assets => ['sensu-plugins-cpu-checks','sensu-ruby-runtime']
    }

    sensu_check { 'check-disk':
      ensure         => 'absent',
      command        => '/opt/sensu-plugins-ruby/embedded/bin/check-disk-usage.rb -p "(\/run|\/sys|\/snap)"',
      interval       => 60,
      subscriptions  => 'linux',
      publish        => true,
      runtime_assets => ['sensu-plugins-cpu-checks','sensu-ruby-runtime']
    }

    sensu_bonsai_asset { 'calebhailey/sensu-deregistration-handler':
      ensure  => 'present'
    }
    
    sensu_bonsai_asset { 'Thor77/sensu-telegram-handler':
      ensure  => 'present'
    }
   
    sensu_handler { 'telegram_ops':
      ensure          => 'present',
      type            => 'pipe',
      command         => 'sensu-telegram-handler --api-token **** --chatid -****',
      timeout         => 10,
      runtime_assets  => ['Thor77/sensu-telegram-handler'],
      filters         => [
        'is_incident',
        'not_silenced'
      ],
    }

    sensu_handler { 'deregistration':
      ensure          => 'present',
      type            => 'pipe',
      command         => 'sensu-deregistration-handler',
      timeout         => 10,
      runtime_assets  => ['calebhailey/sensu-deregistration-handler'],
    }

    include sensu::cli

What is the way to install those plugins?

Of course, this code work fine with 20.04 ( Focal )

@icalvete so installing those plugins (which are the old ruby-based ones) is a bit deprecated. The recommended approach is to use assets to install plugins. In the puppet module, you'd follow this convention, as the plugins you've listed all have updated (and maintained) golang analogs. You'd also use the asset approach to install those ruby checks, along with the ruby runtime.

To clarify a bit further, Sensu is moving away from developing and maintaining Ruby plugins, as they're difficult to ship and maintain as assets. If there's a particular Ruby plugin that you need that cannot be installed using an asset, please open up a request on the Catalog repo and we can work on having a Golang analog of that plugin created.

SOLVED: sensu_bonsai_asset resource need to be only in my backend code. Someway sensu agent knows how to download the dependencies to do the check

Thanks @asachs01 but is not working on agent my code.

I added this resource to both codes, agent and backend.

  sensu_bonsai_asset { 'sensu/check-cpu-usage':
    ensure  => 'present',
    version => 'latest',
  }

If I run puppet agent in a machine with both codes, agent a backend, works fine.
If I run puppet agent in a machine only with my agent code I get...

root@bast01:~# puppet agent -t
Info: Using environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for bast01.mydomain.com
Error: /Stage[main]/MY::Monitoring/Sensu_bonsai_asset[sensu/check-cpu-usage]: Sensu namespace 'default' must be defined or exist

Installation by hand works fine.

root@bast01:/etc/systemd/system# sensuctl asset add sensu/check-cpu-usage
no version specified, using latest: 0.2.2
fetching bonsai asset: sensu/check-cpu-usage:0.2.2
added asset: sensu/check-cpu-usage:0.2.2

You have successfully added the Sensu asset resource, but the asset will not get downloaded until
it's invoked by another Sensu resource (ex. check). To add this runtime asset to the appropriate
resource, populate the "runtime_assets" field with ["sensu/check-cpu-usage"].

AGENT

  class { 'sensu':
    api_host                     => 'sensu3.mydomain.com',
    password                     => '****',
    agent_password               => '****',
    agent_entity_config_password => '****',
    ssl_ca_source => 'puppet:///modules/common/ssl/fluzo-ca.crt',
  }

  include sensu::cli

  sensu_bonsai_asset { 'sensu/check-cpu-usage':
    ensure  => 'present',
    version => 'latest',
  }

  class { 'sensu::agent':
    subscriptions => ['default', 'linux', $hostname, 'nuc']
  }

BACKEND

    class { 'sensu::backend':
      ssl_cert_source => 'puppet:///modules/common/ssl/my.crt',
      ssl_key_source  => 'puppet:///modules/common/ssl/my.key',
      config_hash     => {
        'deregistration-handler' => 'deregistration',
        'event-log-file'         => '/var/log/sensu/events.log'
      }
    }

    sensu_check { 'check-cpu':
      ensure         => 'present',
      command        => 'check-cpu-usage -w 75 -c 85',
      interval       => 60, 
      subscriptions  => 'linux',
      publish        => true,
      runtime_assets => ['sensu/check-cpu-usage']
    }

What i'm doing wrong?. Thanks !!!

@icalvete so the reason it doesnt work is that assets (and by extension, asset definitions) are for the backend only. See https://docs.sensu.io/sensu-go/latest/plugins/use-assets-to-install-plugins/ and https://docs.sensu.io/sensu-go/latest/plugins/assets/. The docs do a useful job of explaining how assets work. Basically, you define an asset, which just tells an agent or backend where to fetch it from, and then on the first invocation of the asset, it's downloaded to the agent or backend cache.