Automatic jenkins master discovery and monitoring using nagios - jenkins

I want a way to automatically discover Jenkins master servers and automatically monitor the health of the jobs on those Jenkins master servers so that I can look at a single console(using nagios host) to detect issues when a job is failing anywhere in integration.
Could someone help me out to finding Jenkins master servers using nagios?

There's a nagios plugin for retrieving job health information from Jenkins, but it looks like it requires manual configuration for each job, see Nagios Jenkins plugin.
I'm not familiar enough with nagios to know how any built-in auto-discovery works, but it looks like there are several example scripts (check_find_new_hosts and device discovery) for generating the necessary configuration from a network scan. You'll have to do some work to integrate the results of the scan into your nagios instance. (IIRC, you need to restart nagios after writing new configuration?)
To get the list of Jenkins servers, you can build on one of the existing network scan scripts for nagios. The script should scan an IP range and identify devices that respond to http://IP:8080/api/xml. The resulting XML document (JSON results are also supported) should contain a root tag named <hudson> (in my instance, maybe this will change to "jenkins" in a future release). If the server responds to this request, then you'll want your script to generate the nagios configuration for monitoring it.
In addition, the XML response will contain a list of jobs, like:
<job>
<name>My Job</name>
<url>http://jenkins:8080/job/My%20job/</url>
<color>blue</color>
</job>
By iterating through this list, you get the job names, job urls (for more details or polling for status), and the current statuses (blue means success). This list of jobs can provide input to the Nagios Jenkins plugin configuration.
The Jenkins Remote API is documented on your Jenkins instance, just go to http://jenkins:8080/api.

Related

Alerting for jenkin jobs stuck with no executors

We have multiple Jenkin masters and have enabled Jenkins Prometheus plugin and connected these masters as data sources to Grafana. I am currently interested in finding jobs which are waiting for executors for more than a certain time and create an alert based on this. I looked at Jenkins metrics but did not find any suitable metric to have monitoring for this use case. How can I achieve this?
You can access the Jenkins build queue via Groovy and check for entries waiting for too long.
It is possible to run Groovy scripts via the Jenkins REST API, which then will be your interface for polling for such "blocked" jobs.

Functionality to start and stop jobs

I am not sure something like Jenkins is built for this functionality, but I am curious if it is possible.
Say I have some sort of code, that I want to run from 7am until 7pm. Typically Jenkins jobs are done when whatever process is complete. Like a python script closing.
my goal would be to be able to have a script that will infinetly run, and will be terminated by Jenkins at a certain time. Doing this would still allow me to see the nice web ui, remotely start it, easily add hooks, etc.
Is this possible in Jenkins, or is there another platform like Jenkins that supports this type of functionality. Basically instead of using Jenkins for 'builds', you would be using them to control services
I have completely replaced Linux Cron with Jenkins, so yeah you can do what you're wanting to do. Only limited by your imagination :)
I have all of my Linux servers configured as nodes (via ssh) within Jenkins, and the connecting account on each of them has sudo privileges, so I can essentially have Jenkins do anything I want it to, at the OS level.

Monitor multiple Jenkins servers health checks in a single Jenkins Server as Dashboard?

I would like to monitor multiple Jenkins servers health checks in a single Jenkins server as dashboard.Can some one let me know what all the options do we have for this ??
Thanks!!
There is no option for managing multiple Jenkins servers health checks in a single Jenkins Server specially on Open source Jenkins. But we can find some similar thing on CloudBees Jenkins where we can integrate Multiple masters together.
CloudBees Jenkins Analytics also make the monitoring of multiple masters easier by adding a number of new graphs.
Please refer the link : https://www.cloudbees.com/blog/jenkins-operations-and-continuous-delivery-scale-cloudbees-jenkins-enterprise

Communicate between Jenkins server without setting up master slave relation

I would like to set up jenkins server that would run test scripts based on successful build deployments on other Jenkins servers. for example, if the QA jenkins server is named JQA1OnMachine1 and i have three others that are named
J2OnMachine2, J3OnMachine3, J4OnMachine4 (different jenkins server on different boxes) can the JQA1OnMachine1 (QA jenkis) poll the others at regular interval to see if a build was deployed successfully? if so can anyone tell me how?
Jenkins master slave along with Jenkins Pipeline Plugin would be one of the better ways to implement this however, since you don't want to use that approach you can explore PSTools to remotely capture processes or files on different server.
Your builds may update a file on the build server post completion of the build and your QA machine can run script with PSTools to monitor and trigger the QA testing based on the file content

How to monitor jenkins build status from external applications

We are developing a reporting application for my organization, which is aimed to monitor jenkins builds for specific jobs. I know there are API to get the status of the jobs and other information. But, it requires me to keep polling jenkins with these api requests. Would like to know, is there any other way like events thrown by jenkins so that my application can listen and do the needful ?
You can "throw" whatever you want in your Jenkins build. Question is: what can you application "catch"?
You can make a POST or GET request at the end of the build to your application.
You can upload files to remote hosts.
You can update files on local host.
You can execute batch or shell scripts, remotely or locally.
So what can your application listen to?
Got this plugin https://wiki.jenkins-ci.org/display/JENKINS/Notification+Plugin, this solves my requirement

Resources