How can i automate the database validation when i calling icingaweb


(Elsonpulikkan96) #1

How can i automate the databse validation when i calling icingaweb


Can i automate the databse validation when i calling icingaweb
(Michael Friedrich) #2

Hi,

can you elaborate a bit more in detail, e.g. how you’ve installed Icinga Web 2, and where you are currently at? Best with a screenshot.

Cheers,
Michael


(Elsonpulikkan96) #3


(Elsonpulikkan96) #4

Hii Michael,

Thanks in advance for your reply,

I need some ideas for automating this step now I am done by manually inputting these database verification steps on browser

Doing icinga2 and icinga2 web UI installing by running ansible playbooks.


(Michael Friedrich) #5

The docs hold some hints on automation, which shouldn’t require the manual web setup wizard. If your playbooks are capable of creating the database beforehand, you can also manage the configuration files. This is a similar thing with puppet-icingaweb2 for example.

Didn’t look into this role, but maybe it has some hints.

Hint: I’m not an Ansible guy, there’s better persons to ask.

Kind regards,
Michael


(Elsonpulikkan96) #6

Thanks for your supports @dnsmichi and i have solved the issue

Very best regards

Elson Pulikkan


(Elsonpulikkan96) #7
---
- name:  Adding repository of icinga2
  shell: add-apt-repository ppa:formorer/icinga -y
  become: yes

- name: Adding repositories of Icinga Web-UI
  apt_key: url=http://packages.icinga.org/icinga.key state=present
  become: yes 

- debconf: name='mysql-server' question='mysql-server/root_password' value='{{mysql_root_pass | quote}}' vtype='password'
  become: yes

- debconf: name='mysql-server' question='mysql-server/root_password_again' value='{{mysql_root_pass | quote}}' vtype='password'
  become: yes

- debconf: name='icinga2-ido-mysql' question='icinga2-ido-mysql/mysql/admin-pass' value='{{mysql_root_pass | quote}}' vtype='password'
  become: yes

- debconf: name='icinga2-ido-mysql' question='icinga2-ido-mysql/db/dbname' value='{{icinga2_mysqlidodb}}' vtype='string'  
  become: yes

- debconf: name='icinga2-ido-mysql' question='icinga2-ido-mysql/mysql/app-pass' value='{{ mysql_root_pass }}' vtype='password'
  become: yes

- debconf: name='icinga2-ido-mysql' question='icinga2-ido-mysql/mysql/app-password-confirm' value='{{ mysql_root_pass }}' vtype='password'
  become: yes

- name: Installing required softwares ( Apache2, php modules, NRPE Plugins, icinga-web ui , Mysql , icinga-IDO )
  apt: name={{ item }} state=present
  become: yes
  with_items:
    - apache2
    - python-pexpect
    - build-essential
    - python-dev
    - libmysqlclient-dev
    - python-mysqldb
    - mysql-server
    - mysql-client
    - php7.0
    - php7.0-mysql
    - libapache2-mod-php7.0
    - php7.0-cli
    - php7.0-cgi
    - php7.0-gd
    - php7.0-mcrypt
    - php-curl
    - unzip
    - php-json 
    - php-gd
    - php-imagick
    - php-pgsql
    - php-intl
    - php-mysql
    - php-ldap
    - icinga2
    - icinga2-ido-mysql
    - icingaweb2

- name: Creating Database User for icinga-web2 module
  command: mysql -u root -p{{ mysql_root_pass }} -e "CREATE USER 'icingaweb2'@'localhost' IDENTIFIED BY '{{ mysql_root_pass }}'"

- name: Grant permission to DB_USER
  command: mysql -u root -p{{ mysql_root_pass }} -e "GRANT ALL PRIVILEGES ON * . * TO 'icingaweb2'@'localhost'"

- name: Creating Database for icinga-web2 module
  command: mysql -u root -p{{ mysql_root_pass }} -e "CREATE DATABASE icingaweb2 CHARACTER SET 'utf8'"

- name: Grant permission to DB_USER
  command: mysql -u root -p{{ mysql_root_pass }} -e "GRANT ALL PRIVILEGES ON * . * TO 'icinga2'@'localhost'"

- name: Flush Privileges
  command: mysql -u root -p{{ mysql_root_pass }} -e "FLUSH PRIVILEGES"

- name: change the timezone of PHP
  lineinfile:
    dest: /etc/php/7.0/apache2/php.ini
    line: 'date.timezone = UTC'
    state: present

- name: Restarting services
  command: "{{ item }}"
  become: yes  
  with_items:
   - sudo icinga2 feature enable ido-mysql
   - sudo icinga2 feature enable command
   - sudo service icinga2 restart
   - sudo service mysql restart
   - sudo service apache2 restart

- name: Adding influxdb details to icinga server
  template:
    src: ido-mysql.conf.j2
    dest: /etc/icinga2/features-enabled/ido-mysql.conf.j2
    mode: 0777

- name: Prefetching configuration values
  command: "{{ item }}"
  become: yes
  with_items:
   - sudo icingacli module enable monitoring
   - sudo icingacli module enable translation
   - sudo /bin/su -c "icingacli setup config webserver apache > /etc/apache2/sites-enabled/icingaweb2.conf"
   - sudo usermod -a -G icingaweb2 www-data

- name: Importing Database Schema
  shell: sudo mysql -u icingaweb2 -D icingaweb2 < /usr/share/icingaweb2/etc/schema/mysql.schema.sql -p{{ mysql_root_pass }}

- name: Generate MD5 Value for Admin_user_pass
  command: openssl passwd -1 {{ icinga_pass }}
  register: openssl_output

- name: Creating Configuration files (icinagweb-UI)
  become: true
  command: "{{ item }}"
  with_items:
   - sudo mysql -u icingaweb2 -D icingaweb2 -p{{ mysql_root_pass }} -e "INSERT INTO icingaweb_user (name, active, password_hash) VALUES ('{{ icinga_user }}', 1, '{{ openssl_output.stdout }}')"
   - sudo mysql -u icingaweb2 -p{{ mysql_root_pass }} -e "FLUSH PRIVILEGES"
   - sudo systemctl restart icinga2.service
   - sudo icingacli setup token create
   - sudo icingacli setup token show
   - sudo /bin/su -c 'icingacli setup config webserver apache --document-root /usr/share/icingaweb2/public > /etc/apache2/conf-available/icingaweb2.conf'
   - sudo mkdir -p /etc/icingaweb2/modules/monitoring/
   
   - sudo /bin/su -c 'echo "library \"db_ido_mysql\"" > /etc/icinga2/features-enabled/ido-mysql.conf'
   - sudo /bin/su -c 'echo "object IdoMysqlConnection \"ido-mysql\" {" >> /etc/icinga2/features-enabled/ido-mysql.conf'
   - sudo /bin/su -c 'echo "  user = \"icinga2\"," >> /etc/icinga2/features-enabled/ido-mysql.conf'
   - sudo /bin/su -c 'echo "  password = \"{{ mysql_root_pass }}\"," >> /etc/icinga2/features-enabled/ido-mysql.conf'
   - sudo /bin/su -c 'echo "  host = \"localhost\"," >> /etc/icinga2/features-enabled/ido-mysql.conf'
   - sudo /bin/su -c 'echo "  database = \"icinga2\"" >> /etc/icinga2/features-enabled/ido-mysql.conf'
   - sudo /bin/su -c 'echo "}" >> /etc/icinga2/features-enabled/ido-mysql.conf'
   
   - sudo /bin/su -c 'echo "[icingaweb2]" > /etc/icingaweb2/authentication.ini'
   - sudo /bin/su -c 'echo "backend = \"db\"" >> /etc/icingaweb2/authentication.ini'
   - sudo /bin/su -c 'echo "resource = \"icingaweb_db\"" >> /etc/icingaweb2/authentication.ini'
   
   - sudo /bin/su -c 'echo "[global]" > /etc/icingaweb2/config.ini'
   - sudo /bin/su -c 'echo "show_stacktraces = \"1\"" >> /etc/icingaweb2/config.ini'
   - sudo /bin/su -c 'echo "config_backend = \"db\"" >> /etc/icingaweb2/config.ini'
   - sudo /bin/su -c 'echo "config_resource = \"icingaweb_db\"" >> /etc/icingaweb2/config.ini'
   - sudo /bin/su -c 'echo "" >> /etc/icingaweb2/config.ini'
   - sudo /bin/su -c 'echo "[logging]" >> /etc/icingaweb2/config.ini'
   - sudo /bin/su -c 'echo "log = \"syslog\"" >> /etc/icingaweb2/config.ini'
   - sudo /bin/su -c 'echo "level = \"ERROR\"" >> /etc/icingaweb2/config.ini'
   - sudo /bin/su -c 'echo "application = \"icingaweb2\"" >> /etc/icingaweb2/config.ini'
   - sudo /bin/su -c 'echo "facility = \"user\"" >> /etc/icingaweb2/config.ini'

   - sudo /bin/su -c 'echo "[icingaweb2]" > /etc/icingaweb2/groups.ini'
   - sudo /bin/su -c 'echo "backend = \"db\"" >> /etc/icingaweb2/groups.ini'
   - sudo /bin/su -c 'echo "resource = \"icingaweb_db\"" >> /etc/icingaweb2/groups.ini'

   - sudo /bin/su -c 'echo "[icingaweb_db]" > /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "type = \"db\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "db = \"mysql\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "host = \"localhost\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "port = \"\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "dbname = \"icingaweb2\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "username = \"icingaweb2\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "password = \"{{ mysql_root_pass }}\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "charset = \"\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "persistent = \"0\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "use_ssl = \"0\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "[icinga_ido]" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "type = \"db\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "db = \"mysql\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "host = \"localhost\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "port = \"\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "dbname = \"icinga2\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "username = \"icinga2\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "password = \"{{ mysql_root_pass }}\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "charset = \"\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "persistent = \"0\"" >> /etc/icingaweb2/resources.ini'
   - sudo /bin/su -c 'echo "use_ssl = \"0\"" >> /etc/icingaweb2/resources.ini'

   - sudo /bin/su -c 'echo "[Administrators]" > /etc/icingaweb2/roles.ini'
   - sudo /bin/su -c 'echo "users = \"{{ icinga_user }}\"" >> /etc/icingaweb2/roles.ini'
   - sudo /bin/su -c 'echo "permissions = \"*\"" >> /etc/icingaweb2/roles.ini'
   - sudo /bin/su -c 'echo "groups = \"Administrators\"" >> /etc/icingaweb2/roles.ini'

   - sudo /bin/su -c 'echo "[icinga]" > /etc/icingaweb2/modules/monitoring/backends.ini'
   - sudo /bin/su -c 'echo "type = \"ido\"" >> /etc/icingaweb2/modules/monitoring/backends.ini'
   - sudo /bin/su -c 'echo "resource = \"icinga_ido\"" >> /etc/icingaweb2/modules/monitoring/backends.ini'
   
   - sudo /bin/su -c 'echo "[icinga2]" > /etc/icingaweb2/modules/monitoring/commandtransports.ini'
   - sudo /bin/su -c 'echo "transport = \"local\"" >> /etc/icingaweb2/modules/monitoring/commandtransports.ini'
   - sudo /bin/su -c 'echo "path = \"var/run/icinga2/cmd/icinga2.cmd\"" >> /etc/icingaweb2/modules/monitoring/commandtransports.ini'
   
   - sudo /bin/su -c 'echo "[security]" > /etc/icingaweb2/modules/monitoring/config.ini'
   - sudo /bin/su -c 'echo "protected_customvars = \"*pw*, *pass*, community\"" >> /etc/icingaweb2/modules/monitoring/config.ini'
   
- name: Configure icinga2 server for client
  script: /home/deploy/stackbuilder-aws/utils/master.sh

- name: Restarting services
  shell: sudo service mysql restart && sudo service icinga2 restart && sudo service apache2 restart && sudo systemctl restart icinga2.service