sstarcher / docker-sensu

Dockerized Sensu - Client, Server, Api
MIT License
103 stars 72 forks source link

Sensu Client doesn't start #48

Closed Northwood128 closed 7 years ago

Northwood128 commented 7 years ago

Howdy!!

I'm trying to create a Sensu Stack in order to have a quick way to instantiate a development stage for Sensu related tools. I found your image very convenient. However I'm having some issues starting the sensu client container.

This is my docker-compose.yml

  version: "3"
  services:
      rabbitmq:
          image: rabbitmq:3.6-management-alpine
          ports:
              - 15672:15672
          environment:
              RABBITMQ_HIPE_COMPILE: 1
              RABBITMQ_ERLANG_COOKIE: 'sarasa'
          networks:
             - my-net
      server:
          image: sstarcher/sensu
          command: server
          links:
              - api
              - rabbitmq
              - redis
          volumes:
              - "./server-conf/server.json:/etc/sensu/config.json"
              - "./logs:/var/log/sensu/"
          networks:
             - my-net
      api:
          image: sstarcher/sensu
          command: api
          links:
              - redis
          ports:
              - '4567:4567'
          volumes:
              - "./api-conf/api.json:/etc/sensu/config.json"
              - "./logs:/var/log/sensu/"
          networks:
             - my-net
      client:
          image: sstarcher/sensu
          command: client
          links:
              - rabbitmq
          volumes:
              - "/dev:/host_dev/:ro"
              - "/proc:/host_proc/:ro"
              - "/sys:/host_sys/:ro"
              - "./client-conf/client.json:/etc/sensu/config.json"
              - "./logs:/var/log/sensu/"
          environment:
              HOST_DEV_DIR: /host_dev
              HOST_PROC_DIR: /host_proc
              HOST_SYS_DIR: /host_sys
          networks:
             - my-net
      uchiwa:
          image: sstarcher/uchiwa
          links:
              - api
          ports:
              - '3000:3000'
          volumes:
              - "./dashboard:/etc/sensu/dashboard.d"
              - "./logs/uchiwa.log:/var/log/uchiwa.log"
          networks:
             - my-net
      redis:
          image: redis:3
          networks:
             - my-net
  networks:
      my-net:

All of the containers start just fine but the one for the client. Is shows this message:

{"timestamp":"2017-06-16T20:37:18.101670+0000","level":"warn","message":"loading config file","file":"/etc/sensu/config.json"}
{"timestamp":"2017-06-16T20:37:18.102094+0000","level":"warn","message":"loading config files from directory","directory":"/etc/sensu/conf.d"}
{"timestamp":"2017-06-16T20:37:18.102367+0000","level":"warn","message":"loading config file","file":"/etc/sensu/conf.d/transport.json"}
{"timestamp":"2017-06-16T20:37:18.102640+0000","level":"warn","message":"config file applied changes","file":"/etc/sensu/conf.d/transport.json","changes":{}}
{"timestamp":"2017-06-16T20:37:18.102879+0000","level":"warn","message":"loading config file","file":"/etc/sensu/conf.d/client.json"}
{"timestamp":"2017-06-16T20:37:18.102981+0000","level":"fatal","message":"config file must be valid json","file":"/etc/sensu/conf.d/client.json","error":"unexpected comma at line 7, column 17 [parse.c:575]"}
{"timestamp":"2017-06-16T20:37:18.103128+0000","level":"fatal","message":"SENSU NOT RUNNING!"}

./client-conf/client.json looks like:

{
  "client": {
    "socket": {
      "bind": "127.0.0.1"
    },
    "name": "4494446b45e0",
    "address": "127.0.0.1",
    "subscriptions": [
        "docker"
    ],
    "keepalive": {
      "thresholds": {
         "warning": 120,
         "critical": 180
      },
      "handler": "default"
    }
  },
  "transport": {
    "name": "redis",
    "reconnect_on_error": true
  },
  "rabbitmq": {
    "host": "rabbitmq",
    "port": 5671,
    "vhost": "/sensu",
    "user": "sensu",
    "password": "secret",
    "heartbeat": 30,
    "prefetch": 50
  }
}

I don't know where it gets that /etc/sensu/conf.d/* config files. Can you lend me a hand? Thanks in advance!

sstarcher commented 7 years ago

The template for the client.json is located here - https://github.com/sstarcher/docker-sensu/blob/master/templates/client.json.tmpl

I would recommend running the container and changing the entrypoint to /bin/sh so you can run the start command yourself and capture the client.json to verify that it's valid.

If you don't intend to use the template that this container provides I would recommend overwriting it with your file ./client-conf/client.json:/etc/sensu/config.json"

sstarcher commented 7 years ago

Looking at the docs the template requires

CLIENT_NAME *no default*
CLIENT_ADDRESS *no default*
Northwood128 commented 7 years ago

I did override it. Check the volumes section under the client definition in the docker-compose.yml file. Is this what you mean? Thanks!

sstarcher commented 7 years ago

Close, but not correct. You overwrote /etc/sensu/config.json not /etc/sensu/conf.d/client.json

Northwood128 commented 7 years ago

Ok ,I did that and I still get the same error. Not only that, the file I mounted on /etc/sensu/conf.d/client.json gets changed by this:

{
  "client": {
    "socket": {
      "bind": "127.0.0.1"
    },
    "name": "51f83f494049",
    "address": ,
    "deregister":  true,

    "subscriptions": [

        "all"

        ,"default"

    ],

    "keepalive": {
      "thresholds": {
         "warning": 120,
         "critical": 180
      },
      "handler": "default"
    }
  }
}

{"timestamp":"2017-06-25T14:48:49.358825+0000","level":"fatal","message":"config file must be valid json","file":"/etc/sensu/conf.d/client.json","error":"unexpected comma at line 7, column 17 [parse.c:575]"}

It looks like its not letting me use my own config file and instead it wants me to set all those env variables. Was it supposed to be like that?

sstarcher commented 7 years ago

Looks like it blindly processes the templates.

sstarcher commented 7 years ago

https://github.com/sstarcher/docker-sensu/blob/master/Dockerfile#L32

Northwood128 commented 7 years ago

I'm gonna try to create a new client definition using only environment variables and I'll let you know how it goes.

sstarcher commented 7 years ago

If you set the 2 required variables it should merge your file with the templated file.

Northwood128 commented 7 years ago

Confirmed. You have to set up those variables in the docker-compose.yml file. You can't just use a configuration file. Thanks! It works now.

amirhmi commented 6 years ago

I have the same problem and error .

But I don't get what you did for this purpose.

Can you tell me how you made that work?

arecalde-edrans commented 6 years ago

Hi @amirhmi ! If you read above, you can see that what I did was set up those environment variables on my docker-compose.yml

CLIENT_NAME: 'something'
CLIENT_ADDRESS: '127.0.0.1'
amirhmi commented 6 years ago

Can I run that with docker run and only change env variables?

@arecalde-edrans

arecalde-edrans commented 6 years ago

Yeah. With -e

amirhmi commented 6 years ago

thank you very much @arecalde-edrans