1 /******************************************************************************
3 * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
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. *
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. *
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 ******************************************************************************/
23 #include "methods/randomchecktask.hpp"
24 #include "icinga/perfdatavalue.hpp"
25 #include "base/utility.hpp"
26 #include "base/convert.hpp"
27 #include "base/function.hpp"
28 #include "base/logger.hpp"
30 using namespace icinga;
32 REGISTER_SCRIPTFUNCTION(RandomCheck, &RandomCheckTask::ScriptFunc);
34 void RandomCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr,
35 const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
37 if (resolvedMacros && !useResolvedMacros)
40 String output = "Hello from ";
41 output += Utility::GetFQDN();
43 Array::Ptr perfdata = new Array();
44 perfdata->Add(new PerfdataValue("time", Convert::ToDouble(Utility::GetTime())));
46 cr->SetOutput(output);
47 cr->SetPerformanceData(perfdata);
48 cr->SetState(static_cast<ServiceState>(Utility::Random() % 4));
50 service->ProcessCheckResult(cr);