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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/icinga2/downtimes.rb', line 7
def addDowntime( params = {} )
name = params.dig(:name)
hostName = params.dig(:host)
hostGroup = params.dig(:host_group)
startTime = params.dig(:start_time) || Time.now.to_i
endTime = params.dig(:end_time)
author = params.dig(:author)
= params.dig(:comment)
type = params.dig(:type)
filter = nil
if( name == nil )
return {
:status => 404,
:message => 'missing downtime name'
}
end
if( ['host','service'].include?(type.downcase) == false )
return {
:status => 404,
:message => "wrong downtype type. only 'host' or' service' allowed ('#{type}' giving"
}
else
type.capitalize!
end
if( hostGroup != nil && hostName != nil )
return {
:status => 404,
:message => 'choose host or host_group, not both'
}
end
if( hostName != nil )
filter = sprintf( 'host.name=="%s"', hostName )
elsif( hostGroup != nil )
filter = sprintf( '"%s" in host.groups', hostGroup )
else
return {
:status => 404,
:message => 'missing host or host_group for downtime'
}
end
if( == nil )
return {
:status => 404,
:message => 'missing downtime comment'
}
end
if( author == nil )
return {
:status => 404,
:message => 'missing downtime author'
}
else
if( self.existsUser?( author ) == false )
return {
:status => 404,
:message => "these author ar not exists: #{author}"
}
end
end
if( endTime == nil )
return {
:status => 404,
:message => 'missing end_time'
}
else
if( endTime.to_i <= startTime )
return {
:status => 404,
:message => 'end_time are equal or smaller then start_time'
}
end
end
payload = {
"type" => type,
"start_time" => startTime,
"end_time" => endTime,
"author" => author,
"comment" => ,
"fixed" => true,
"duration" => 30,
"filter" => filter
}
result = Network.post( {
:host => name,
:url => sprintf( '%s/v1/actions/schedule-downtime', @icingaApiUrlBase ),
:headers => @headers,
:options => @options,
:payload => payload
} )
logger.debug( result.class.to_s )
return JSON.pretty_generate( result )
end
|