Anna Arhipova | 76b1f93 | 2022-08-05 10:07:32 +0200 | [diff] [blame^] | 1 | import hudson.node_monitors.* |
| 2 | import hudson.slaves.* |
| 3 | import java.util.concurrent.* |
| 4 | |
| 5 | jenkins = Jenkins.instance |
| 6 | |
| 7 | import javax.mail.internet.*; |
| 8 | import javax.mail.* |
| 9 | import javax.activation.* |
| 10 | |
| 11 | def 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 | |
| 19 | def agentAccessible(computer) { |
| 20 | getEnviron(computer)?.get('PATH') != null |
| 21 | } |
| 22 | |
| 23 | def numberOfflineNodes = 0 |
| 24 | def numberNodes = 0 |
| 25 | for (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 | } |
| 58 | println ("Number of Offline Nodes: " + numberOfflineNodes) |
| 59 | println ("Number of Nodes: " + numberNodes) |
| 60 | |