summaryrefslogtreecommitdiffstats
path: root/modules/monitoring/library/Monitoring/Object/Acknowledgement.php
blob: 3cd0d2011a044411003c84cbe82db0cba6410ca1 (plain)
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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
/* Icinga Web 2 | (c) 2015 Icinga Development Team | GPLv2+ */

namespace Icinga\Module\Monitoring\Object;

use InvalidArgumentException;
use Traversable;
use Icinga\Util\StringHelper;

/**
 * Acknowledgement of a host or service incident
 */
class Acknowledgement
{
    /**
     * Author of the acknowledgement
     *
     * @var string
     */
    protected $author;

    /**
     * Comment of the acknowledgement
     *
     * @var string
     */
    protected $comment;

    /**
     * Entry time of the acknowledgement
     *
     * @var int
     */
    protected $entryTime;

    /**
     * Expiration time of the acknowledgment
     *
     * @var int|null
     */
    protected $expirationTime;

    /**
     * Whether the acknowledgement is sticky
     *
     * Sticky acknowledgements suppress notifications until the host or service recovers
     *
     * @var bool
     */
    protected $sticky = false;

    /**
     * Create a new acknowledgement of a host or service incident
     *
     * @param array|object|Traversable $properties
     *
     * @throws InvalidArgumentException If the type of the given properties is invalid
     */
    public function __construct($properties = null)
    {
        if ($properties !== null) {
            $this->setProperties($properties);
        }
    }

    /**
     * Get the author of the acknowledgement
     *
     * @return string
     */
    public function getAuthor()
    {
        return $this->author;
    }

    /**
     * Set the author of the acknowledgement
     *
     * @param   string $author
     *
     * @return  $this
     */
    public function setAuthor($author)
    {
        $this->author = (string) $author;
        return $this;
    }

    /**
     * Get the comment of the acknowledgement
     *
     * @return string
     */
    public function getComment()
    {
        return $this->comment;
    }

    /**
     * Set the comment of the acknowledgement
     *
     * @param   string $comment
     *
     * @return  $this
     */
    public function setComment($comment)
    {
        $this->comment = (string) $comment;

        return $this;
    }

    /**
     * Get the entry time of the acknowledgement
     *
     * @return int
     */
    public function getEntryTime()
    {
        return $this->entryTime;
    }

    /**
     * Set the entry time of the acknowledgement
     *
     * @param   int $entryTime
     *
     * @return  $this
     */
    public function setEntryTime($entryTime)
    {
        $this->entryTime = (int) $entryTime;

        return $this;
    }

    /**
     * Get the expiration time of the acknowledgement
     *
     * @return int|null
     */
    public function getExpirationTime()
    {
        return $this->expirationTime;
    }

    /**
     * Set the expiration time of the acknowledgement
     *
     * @param   int|null $expirationTime Unix timestamp
     *
     * @return  $this
     */
    public function setExpirationTime($expirationTime = null)
    {
        $this->expirationTime = $expirationTime !== null ? (int) $expirationTime : null;

        return $this;
    }

    /**
     * Get whether the acknowledgement is sticky
     *
     * @return bool
     */
    public function getSticky()
    {
        return $this->sticky;
    }

    /**
     * Set whether the acknowledgement is sticky
     *
     * @param   bool $sticky
     *
     * @return  $this
     */
    public function setSticky($sticky = true)
    {
        $this->sticky = (bool) $sticky;
        return $this;
    }

    /**
     * Get whether the acknowledgement expires
     *
     * @return bool
     */
    public function expires()
    {
        return $this->expirationTime !== null;
    }

    /**
     * Set the properties of the acknowledgement
     *
     * @param   array|object|Traversable $properties
     *
     * @return  $this
     * @throws  InvalidArgumentException If the type of the given properties is invalid
     */
    public function setProperties($properties)
    {
        if (! is_array($properties) && ! is_object($properties) && ! $properties instanceof Traversable) {
            throw new InvalidArgumentException('Properties must be either an array or an instance of Traversable');
        }
        foreach ($properties as $name => $value) {
            $setter = 'set' . ucfirst(StringHelper::cname($name));
            if (method_exists($this, $setter)) {
                $this->$setter($value);
            }
        }
        return $this;
    }
}