lippserd / docker-compose-icinga

docker-compose Icinga stack
92 stars 85 forks source link

Include Icinga module for vSphere® #17

Open kratzersmz opened 2 years ago

kratzersmz commented 2 years ago

Hi,

i can enable vsphere module, create vsphere db + user. But i cant find the place where i put: /usr/bin/icingacli vspheredb daemon run

icinga2 container doesnt have icingacli installed, any hints on this?

greets

t3easy commented 2 years ago

I created a 2nd container with the same image, environment and volumes like the Icinga Web 2 container but with

command: ["icingacli","vspheredb","daemon","run"]
entrypoint: []

Same for the Director Daemon.

lippserd commented 2 years ago

I created a 2nd container with the same image, environment and volumes like the Icinga Web 2 container but with

command: ["icingacli","vspheredb","daemon","run"]
entrypoint: []

Same for the Director Daemon.

This is a very smart approach! The Director setup is implemented with PR #33, but not yet the Icinga module for vSphere®.

t3easy commented 2 years ago

@lippserd Cool! The x509 plugin also needs a daemon, that can be created like that.

lippserd commented 2 years ago

@lippserd Cool! The x509 plugin also needs a daemon, that can be created like that.

Yeah, I forgot about that one 😆

t3easy commented 2 years ago

I also thought about using Ofelia for some tasks in the stack, but for now, the daemon containers fits my needs. BTW.: do you have a good idea for icingacli checks? As web and icinga are splitted, the checks can't run as there is no icingacli.

lippserd commented 2 years ago

BTW.: do you have a good idea for icingacli checks? As web and icinga are splitted, the checks can't run as there is no icingacli.

Maybe a Phar of the icingacli plus configuration deployed to the Icinga container. But I don't know if creating the Phar works that easily.

t3easy commented 2 years ago

@lippserd maybe we could discuss the possible solutions somewhere else. I extended this stack to my needs with influxdb and grafana and Traefik as reverse proxy. I could contribute back some examples.

johnfelipe commented 2 years ago

https://github.com/Icinga/icingaweb2-module-vspheredb/issues/389#issuecomment-1238553420

im folling steps for deploy locally vspheredb, but how can create database in docker? is possible guide me with another gist or markdown for test?

johnfelipe commented 2 years ago

pls i need help asap

t3easy commented 2 years ago

First, you must add an additional MariaDB service to the docker-compose.yml with a dedicated volume for the databases. e.g.:

services:
  # ...
  vspheredb-db:
    image: mariadb:${MARIADB_VERSION}
    command:
    - --character-set-server=utf8mb4
    - --collation-server=utf8mb4_bin
    environment:
      MARIADB_DATABASE: vspheredb
      MARIADB_USER: vspheredb
      MARIADB_PASSWORD: ${MARIADB_PASSWORD_VSPHEREDB:?MARIADB_PASSWORD_VSPHEREDB required}
      MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD_VSPHEREDB:?MARIADB_ROOT_PASSWORD_VSPHEREDB required}
      TZ: ${TZ:?TZ required}
    restart: "${RESTART:-always}"
    volumes:
    - vspheredb-db:/var/lib/mysql
  # ...
volumes:
  # ...
  vspheredb-db:

You can also add the config to your icingaweb service.

# ...
services:
  icingaweb:
    # ...
    environment:
      # ...
      icingaweb.resources.vspheredb-db.charset: utf8mb4
      icingaweb.resources.vspheredb-db.db: mysql
      icingaweb.resources.vspheredb-db.dbname: vspheredb
      icingaweb.resources.vspheredb-db.host: vspheredb-db
      icingaweb.resources.vspheredb-db.password: ${MARIADB_PASSWORD_VSPHEREDB:?MARIADB_PASSWORD_VSPHEREDB required}
      icingaweb.resources.vspheredb-db.type: db
      icingaweb.resources.vspheredb-db.username: vspheredb
      icingaweb.modules.vspheredb.config.db.resource: vspheredb-db
      # ...

Then, if necessary, you can cat the sql file from the icingaweb service to the vsphere-db service.

docker compose exec -T icingaweb2 cat /usr/share/icingaweb2/modules/vspheredb/schema/mysql.sql | docker-compose exec -T vspheredb-db sh -c 'exec mysql -u"$MARIADB_USER" -p"$MARIADB_PASSWORD" "$MARIADB_DATABASE"'
johnfelipe commented 2 years ago

First, you must add an additional MariaDB service to the docker-compose.yml with a dedicated volume for the databases. e.g.:

services:
  # ...
  vspheredb-db:
    image: mariadb:${MARIADB_VERSION}
    command:
    - --character-set-server=utf8mb4
    - --collation-server=utf8mb4_bin
    environment:
      MARIADB_DATABASE: vspheredb
      MARIADB_USER: vspheredb
      MARIADB_PASSWORD: ${MARIADB_PASSWORD_VSPHEREDB:?MARIADB_PASSWORD_VSPHEREDB required}
      MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD_VSPHEREDB:?MARIADB_ROOT_PASSWORD_VSPHEREDB required}
      TZ: ${TZ:?TZ required}
    restart: "${RESTART:-always}"
    volumes:
    - vspheredb-db:/var/lib/mysql
  # ...
volumes:
  # ...
  vspheredb-db:

You can also add the config to your icingaweb service.

# ...
services:
  icingaweb:
    # ...
    environment:
      # ...
      icingaweb.resources.vspheredb-db.charset: utf8mb4
      icingaweb.resources.vspheredb-db.db: mysql
      icingaweb.resources.vspheredb-db.dbname: vspheredb
      icingaweb.resources.vspheredb-db.host: vspheredb-db
      icingaweb.resources.vspheredb-db.password: ${MARIADB_PASSWORD_VSPHEREDB:?MARIADB_PASSWORD_VSPHEREDB required}
      icingaweb.resources.vspheredb-db.type: db
      icingaweb.resources.vspheredb-db.username: vspheredb
      icingaweb.modules.vspheredb.config.db.resource: vspheredb-db
      # ...

Then, if necessary, you can cat the sql file from the icingaweb service to the vsphere-db service.

docker compose exec -T icingaweb2 cat /usr/share/icingaweb2/modules/vspheredb/schema/mysql.sql | docker-compose exec -T vspheredb-db sh -c 'exec mysql -u"$MARIADB_USER" -p"$MARIADB_PASSWORD" "$MARIADB_DATABASE"'

this is my compose

https://gist.github.com/e8ded126ce3b82212e2e199e4c6d334c

and run that command show me this:

root@ubuntu20virgen:~/docker-compose-icinga# docker compose exec -T icingaweb2 cat /usr/share/icingaweb2/modules/vspheredb/schema/mysql.sql | docker-compose exec -T vspheredb-db sh -c 'exec mysql -u"$MARIADB_USER" -p"$MARIADB_PASSWORD" "$MARIADB_DATABASE"'
unknown shorthand flag: 'T' in -T
See 'docker --help'.

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/root/.docker")
  -c, --context string     Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var
                           and default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  app*        Docker App (Docker Inc., v0.9.1-beta3)
  builder     Manage builds
  buildx*     Docker Buildx (Docker Inc., v0.8.2-docker)
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  scan*       Docker Scan (Docker Inc., v0.17.0)
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.

To get more help with docker, check out our guides at https://docs.docker.com/go/guides/

how solve it?

t3easy commented 2 years ago

I use docker compose v2 which is a plug-in for docker itself and therefor a subcommand of the docker binary. If you use docker compose v1 use your docker-compose binary instead.

johnfelipe commented 2 years ago

https://gist.github.com/e8ded126ce3b82212e2e199e4c6d334c That is correct?

johnfelipe commented 2 years ago
root@ubuntu20virgen:~/docker-compose-icinga# docker logs -f icinga-playground-mysql-1 2>&1 | grep "GENERATED ROOT PASSWORD"
2022-09-20 17:40:44+00:00 [Note] [Entrypoint]: GENERATED ROOT PASSWORD: VeA<`A;`N=kR{mh4$Y?sN%M-X`/rn)?F
^C
root@ubuntu20virgen:~/docker-compose-icinga# docker exec -ti icinga-playground_mysql_1 /bin/bash
Error: No such container: icinga-playground_mysql_1
root@ubuntu20virgen:~/docker-compose-icinga# docker exec -ti icinga-playground-mysql-1 /bin/bash
root@9f4f8f16603f:/# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 87
Server version: 10.7.5-MariaDB-1:10.7.5+maria~ubu2004 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| director           |
| icingadb           |
| icingaweb          |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
7 rows in set (0.004 sec)

MariaDB [(none)]> CREATE DATABASE vspheredb CHARACTER SET 'utf8mb4' COLLATE utf8mb4_bin;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> CREATE USER vspheredb@localhost IDENTIFIED BY 'icinga2022';
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> GRANT ALL ON vspheredb.* TO vspheredb@localhost;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> Bye
root@9f4f8f16603f:/# exit
root@ubuntu20virgen:~/docker-compose-icinga# docker compose exec -T icingaweb2 cat /usr/share/icingaweb2/modules/vspheredb/schema/mysql.sql | docker-compose exec -T vspheredb-db sh -c 'exec mysql -u"$MARIADB_USER" -p"$MARIADB_PASSWORD" "$MARIADB_DATABASE"'
invalid interpolation format for services.icingaweb.environment.icingaweb.resources.vspheredb-db.password: "required variable MARIADB_PASSWORD_VSPHEREDB is missing a value: MARIADB_PASSWORD_VSPHEREDB required". You may need to escape any $ with another $

what im wrong?

johnfelipe commented 2 years ago

anyone?

      MARIADB_PASSWORD: ${MARIADB_PASSWORD_VSPHEREDB:?MARIADB_PASSWORD_VSPHEREDB required}
      MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD_VSPHEREDB:?MARIADB_ROOT_PASSWORD_VSPHEREDB required}

that one where can setup?