]> granicus.if.org Git - icinga2/blob - lib/methods/nullchecktask.cpp
Move PerfdataValue() class into base library
[icinga2] / lib / methods / nullchecktask.cpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/)  *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #ifndef _WIN32
21 #       include <stdlib.h>
22 #endif /* _WIN32 */
23 #include "methods/nullchecktask.hpp"
24 #include "icinga/icingaapplication.hpp"
25 #include "base/utility.hpp"
26 #include "base/perfdatavalue.hpp"
27 #include "base/convert.hpp"
28 #include "base/function.hpp"
29 #include "base/logger.hpp"
30
31 using namespace icinga;
32
33 REGISTER_SCRIPTFUNCTION_NS(Internal, NullCheck, &NullCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
34
35 void NullCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr,
36     const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
37 {
38         if (resolvedMacros && !useResolvedMacros)
39                 return;
40
41         String output = "Hello from ";
42         output += IcingaApplication::GetInstance()->GetNodeName();
43
44         Array::Ptr perfdata = new Array();
45         perfdata->Add(new PerfdataValue("time", Convert::ToDouble(Utility::GetTime())));
46
47         cr->SetOutput(output);
48         cr->SetPerformanceData(perfdata);
49         cr->SetState(ServiceOK);
50
51         service->ProcessCheckResult(cr);
52 }