1 // +------------------------------------------------------------------+
2 // |             ____ _               _        __  __ _  __           |
3 // |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
4 // |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
5 // |           | |___| | | |  __/ (__|   <    | |  | | . \            |
6 // |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
7 // |                                                                  |
8 // | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
9 // +------------------------------------------------------------------+
10 //
11 // This file is part of Check_MK.
12 // The official homepage is at http://mathias-kettner.de/check_mk.
13 //
14 // check_mk is free software;  you can redistribute it and/or modify it
15 // under the  terms of the  GNU General Public License  as published by
16 // the Free Software Foundation in version 2.  check_mk is  distributed
17 // in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
18 // out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
19 // PARTICULAR PURPOSE. See the  GNU General Public License for more de-
20 // ails.  You should have  received  a copy of the  GNU  General Public
21 // License along with GNU Make; see the file  COPYING.  If  not,  write
22 // to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
23 // Boston, MA 02110-1301 USA.
24 
25 #include "DowntimeOrComment.h"
26 #include <stdlib.h>
27 #include <string.h>
28 
DowntimeOrComment(nebstruct_downtime_struct * dt,unsigned long id)29 DowntimeOrComment::DowntimeOrComment(nebstruct_downtime_struct *dt,
30                                      unsigned long id)
31     : _type(dt->downtime_type)
32     , _entry_time(dt->entry_time)
33     , _author_name(strdup(dt->author_name))
34     , _comment(strdup(dt->comment_data))
35     , _id(id) {
36     _host = find_host(dt->host_name);
37     if (dt->service_description != nullptr) {
38         _service = find_service(dt->host_name, dt->service_description);
39         _is_service = 1;
40     } else {
41         _service = nullptr;
42         _is_service = 0;
43     }
44 }
45 
~DowntimeOrComment()46 DowntimeOrComment::~DowntimeOrComment() {
47     free(_author_name);
48     free(_comment);
49 }
50 
Downtime(nebstruct_downtime_struct * dt)51 Downtime::Downtime(nebstruct_downtime_struct *dt)
52     : DowntimeOrComment(dt, dt->downtime_id)
53     , _start_time(dt->start_time)
54     , _end_time(dt->end_time)
55     , _fixed(dt->fixed)
56     , _duration(dt->duration)
57     , _triggered_by(dt->triggered_by) {}
58 
Comment(nebstruct_comment_struct * co)59 Comment::Comment(nebstruct_comment_struct *co)
60     : DowntimeOrComment(reinterpret_cast<nebstruct_downtime_struct *>(co),
61                         co->comment_id)
62     , _expire_time(co->expire_time)
63     , _persistent(co->persistent)
64     , _source(co->source)
65     , _entry_type(co->entry_type)
66     , _expires(co->expires) {}
67