forked from cloudbees/jenkins-scripts
-
Notifications
You must be signed in to change notification settings - Fork 6
/
shared-agent-report-online-busy.groovy
42 lines (36 loc) · 1.03 KB
/
shared-agent-report-online-busy.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
Author: Kuisathaverat
Since: April 2017
Description: Check the status of all Shared Agents
Scope: Cloudbees Jenkins Operations Center
**/
import java.util.*
import jenkins.model.*
import hudson.model.*
import hudson.slaves.*
import static com.cloudbees.opscenter.server.persistence.SlaveLeaseTable.getLeases;
boolean reportError = false
def checkSharedAgentOffline(aSlave) {
println "Agent: " + aSlave.name
def online = false
def busy = false
if (aSlave instanceof com.cloudbees.opscenter.server.model.SharedSlave) {
online = aSlave.getOfflineCause() == null
def leases = getLeases(aSlave.getUid())
busy = leases != null && !leases.isEmpty()
}
println('\tIs Online: ' + online)
println('\tIs Busy: ' + busy)
if(!online){
reportError = true
}
}
// CJOC Shared Slaves
Jenkins.instance.allItems.grep {
it.class.name == 'com.cloudbees.opscenter.server.model.SharedSlave'
}.each {
checkSharedAgentOffline(it)
}
if(reportError){
println 'Some Shared Agents are offline!!!'
}