1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package ch.syabru.nagios.broker.impl;
17
18 import java.io.IOException;
19 import java.io.Writer;
20 import java.util.Date;
21
22 import org.apache.commons.lang.Validate;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import ch.syabru.nagios.broker.ExternalCommand;
27
28
29
30
31
32
33
34 public class ScheduleServiceCheckCommand implements ExternalCommand {
35 private static final Logger logger = LoggerFactory.getLogger(
36 ScheduleServiceCheckCommand.class);
37
38 private static final String COMMAND = "SCHEDULE_SVC_CHECK";
39
40 private String hostName;
41 private String serviceDescription;
42 private Date checkTime;
43
44
45
46
47
48
49
50 public ScheduleServiceCheckCommand(String hostName,
51 String serviceDescription, Date checkTime)
52 {
53 Validate.notNull(hostName, "hostName must not be null");
54 Validate.notNull(serviceDescription,
55 "serviceDescription must not be null");
56 Validate.notNull(checkTime, "checkTime must not be null");
57 this.hostName = hostName;
58 this.serviceDescription = serviceDescription;
59 this.checkTime = checkTime;
60 }
61
62 @Override
63 public void writeCommand(Writer writer) throws IOException
64 {
65 StringBuilder sb = new StringBuilder();
66 sb.append("[");
67 sb.append(Long.toString(System.currentTimeMillis() / 1000));
68 sb.append("] ");
69 sb.append(COMMAND);
70 sb.append(";");
71 sb.append(hostName);
72 sb.append(";");
73 sb.append(serviceDescription);
74 sb.append(";");
75 sb.append(Long.toString(checkTime.getTime() / 1000));
76 sb.append("\n");
77 writer.write(sb.toString());
78 writer.flush();
79 logger.debug(sb.toString());
80 }
81
82 public String getHostName() {
83 return hostName;
84 }
85
86 public String getServiceDescription() {
87 return serviceDescription;
88 }
89
90 public Date getCheckTime() {
91 return checkTime;
92 }
93 }