blob: eb2ccd8de1fdf3fed1f8c41b767d5632db37aecf [file] [log] [blame]
Anna Arhipova76b1f932022-08-05 10:07:32 +02001import hudson.node_monitors.*
2import hudson.slaves.*
3import java.util.concurrent.*
4
5jenkins = Jenkins.instance
6
7import javax.mail.internet.*;
8import javax.mail.*
9import javax.activation.*
10
11def getEnviron(computer) {
12 def env
13 def thread = Thread.start("Getting env from ${computer.name}", { env = computer.environment })
14 thread.join(2000)
15 if (thread.isAlive()) thread.interrupt()
16 env
17}
18
19def agentAccessible(computer) {
20 getEnviron(computer)?.get('PATH') != null
21}
22
23def numberOfflineNodes = 0
24def numberNodes = 0
25for (agent in jenkins.getNodes()) {
26 def computer = agent.computer
27 numberNodes ++
28 println ""
29 println "Checking computer ${computer.name}:"
30 def isOK = (agentAccessible(computer) && !computer.offline)
31 if (isOK) {
32 println "\t\tOK, got PATH back from agent ${computer.name}."
33
34 } else {
35 numberOfflineNodes ++
36 println " ERROR: can't get PATH from agent ${computer.name}."
37 //if (computer.isTemporarilyOffline()) {
38 // if (!computer.getOfflineCause().toString().contains("Disconnected by")) {
39 // computer.setTemporarilyOffline(false, agent.getComputer().getOfflineCause())
40 // }
41 //} else {
42 // //computer.connect(true)
43 //}
44
45 if (computer.isOffline() && !computer.isTemporarilyOffline())
46 {
47 println "!!!! this node will be killed !!!";
48 computer.doDoDelete();
49 }
50 }
51 println('\tcomputer.isOffline: ' + computer.isOffline());
52 println('\tcomputer.isTemporarilyOffline: ' + computer.isTemporarilyOffline());
53 println('\tcomputer.getOfflineCause: ' + computer.getOfflineCause());
54 println('\tcomputer.offline: ' + computer.offline);
55 time = computer.getIdleStartMilliseconds() ;
56 println('\tcomputer.getConnectTime: ' + new Date(time).toString());
57 }
58println ("Number of Offline Nodes: " + numberOfflineNodes)
59println ("Number of Nodes: " + numberNodes)
60