jjethwa / icinga2

GNU General Public License v3.0
223 stars 189 forks source link

Opsgenie Integration requirements #239

Open ysibirski opened 4 years ago

ysibirski commented 4 years ago

Hi there, I have been recently working on integrating new OpsGenie OEC connector with Icinga2 container and faced couple of things that I have decided to ask you about. OEC connector is using python3 scripts to communicate with Icinga2 and has one python module requirement(python3-requests). Is it possible and of course if you feel ok making two small adjustments to Icinga2 image:

  1. Make python3 as default python using something like this for exmample: cd /usr/bin && ln -sf python3 python
  2. Install python3-requests apt package inside the Image.

Currently, I made it working in jenkins pipeline using the following adjustments, but they can be simplified to just only starting OEC connector which would be great.

stage('Enable OpsGenie Integration') {
            steps {
                sh (
                    script: """
                        set +xe

                        # Making sure python3 is default
                        docker exec icinga2 /bin/bash -c "cd /usr/bin && ln -sf python3 python"

                        # Checking if python3-requests package is installed
                        docker exec icinga2 /bin/bash -c "dpkg -s python3-requests &>/dev/null"

                        if [[ \$? -ne 0 ]]; then
                            docker exec icinga2 /bin/bash -c "apt update -qq && apt -y install python3-requests"
                        fi

                        # Starting OpsGenie Connector if it is not running
                        OEC_PID=\$(docker exec icinga2 /bin/bash -c "pgrep -f OpsgenieEdgeConnector")

                        if [[ "\${OEC_PID}" == "" ]]; then
                            docker exec -d icinga2 /bin/bash -c "OEC_CONF_SOURCE_TYPE='local' OEC_CONF_LOCAL_FILEPATH='/home/opsgenie/oec/conf/config.json' /home/opsgenie/oec/OpsgenieEdgeConnector"
                        fi
                        docker exec icinga2 /bin/bash -c "sudo chown -R ${NAGIOS_UID} /var/log/opsgenie"
                    """,
                    returnStatus: true
                )
            }

Thank you very much in advance for all the comments and replies. Hope this request will reach the right place.

Best, Yuri.

jjethwa commented 4 years ago

Hi @lumi-yuri

Thanks so much for doing the groundwork on this. My only concern is that some of the default check scripts might be still using python2. Have you noticed any issues with your build?

ysibirski commented 4 years ago

@jjethwa thank you for your quick response on this. I did not notice any issue yet and currently working on cutting over from our old Icinga1 to new Icinga2 running inside the container created from your Image and integrated with OpsGenie and slack. Everything works as charm so far with a bit of crafty modification to the image that I mentioned: default python and python3-request apt package install. However, I am not using any of existing default nagios plugins(we are using Icinga2 --> nagios integration) that are written in python. At the same time python 2 reached its EOL seems like on January 1st 2020. I am also happy to share my OpsGenie OEC connector integration config files if that can be helpful for someone here.

$ docker exec -it icinga2 /bin/bash -c "ls -l /usr/lib/nagios/plugins/*.py"
lrwxrwxrwx 1 root root    13 Mar  1  2019 /usr/lib/nagios/plugins/check_mongodb.py -> check_mongodb
-rwxr-xr-x 1 root root 19894 Mar  1  2019 /usr/lib/nagios/plugins/pmp-check-aws-rds.py
-rwxr-xr-x 1 root root 27428 Mar  1  2019 /usr/lib/nagios/plugins/pmp-check-mongo.py

Thank you in advance, Yuri.

jjethwa commented 4 years ago

Thanks @lumi-yuri

I'll do some testing over the next few days with the default container setup and python3 and if I don't run into any issues, add the lines as you suggested.

Your config files would be really helpful and thanks for wanting to share them. What I would suggest is creating a public git repository to share them, similar to what I did for the Slack notification script and config files: https://github.com/jjethwa/icinga2-slack-notification There's also the Icinga Exchange: https://exchange.icinga.com/

ysibirski commented 4 years ago

@jjethwa thank you very much. There will be two extra lines as a desired state. One will make python3 as default and the other one will install python3-requests package that makes python module requests which is being used by opsgenie integration available to the system. Apt package installation can be nicely embedded into your Dockerfile where you are already installing some apt packages. I will share my opsgenie config with the people. The only drawback is you have to start OEC connector on each container reboot. Not sure if this is the best solution but works for me :+1:

`# Starting OpsGenie Connector if it is not running OEC_PID=\$(docker exec icinga2 /bin/bash -c "pgrep -f OpsgenieEdgeConnector")

                    if [[ "\${OEC_PID}" == "" ]]; then
                        docker exec -d icinga2 /bin/bash -c "OEC_CONF_SOURCE_TYPE='local' OEC_CONF_LOCAL_FILEPATH='/home/opsgenie/oec/conf/config.json' /home/opsgenie/oec/OpsgenieEdgeConnector"
                    fi
                    docker exec icinga2 /bin/bash -c "sudo chown -R ${NAGIOS_UID} /var/log/opsgenie"`

Thank you again in advance, Yuri.

jjethwa commented 4 years ago

@lumi-yuri

How about using Supervisor to manage the connector? It's already being used in the container to run the other daemons like Icinga2, MariaDB, httpd, etc

ysibirski commented 4 years ago

@jjethwa it is not a bad idea, but we are trying to avoid modifying your base image and building our own from yours. That will make our lives easier with upgrades and such. At some point I was thinking of going this path but then if we only have to execute one command: docker exec -d icinga2 /bin/bash -c "OEC_CONF_SOURCE_TYPE='local' OEC_CONF_LOCAL_FILEPATH='/home/opsgenie/oec/conf/config.json' /home/opsgenie/oec/OpsgenieEdgeConnector" it should be absolutely fine.

Best, Yuri.

jjethwa commented 4 years ago

Hi @lumi-yuri

Sorry for the delay, I'm still working on this, but a bit slower as it's crunch time at work. I should be able to get it done late next week.

ysibirski commented 4 years ago

No worries @jjethwa. Take your time.