mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-28 16:14:09 +02:00
parent
a24c233ecb
commit
d79680c642
@ -17,7 +17,11 @@
|
|||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
#include "icinga/nullchecktask.h"
|
#include "icinga/nullchecktask.h"
|
||||||
|
#include "base/utility.h"
|
||||||
#include "base/scriptfunction.h"
|
#include "base/scriptfunction.h"
|
||||||
#include "base/logger_fwd.h"
|
#include "base/logger_fwd.h"
|
||||||
#include <boost/smart_ptr/make_shared.hpp>
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
@ -36,9 +40,30 @@ Dictionary::Ptr NullCheckTask::ScriptFunc(const Service::Ptr&)
|
|||||||
String output = "Hello from ";
|
String output = "Hello from ";
|
||||||
output += name;
|
output += name;
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
unsigned int seed = Utility::GetPid() * time(NULL);
|
||||||
|
int state = rand_r(&seed) % 4;
|
||||||
|
#else
|
||||||
|
int state = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
Dictionary::Ptr cr = boost::make_shared<Dictionary>();
|
Dictionary::Ptr cr = boost::make_shared<Dictionary>();
|
||||||
cr->Set("output", output);
|
cr->Set("output", output);
|
||||||
cr->Set("state", StateOK);
|
cr->Set("state", ExitStatusToState(state));
|
||||||
|
|
||||||
return cr;
|
return cr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServiceState NullCheckTask::ExitStatusToState(int exitStatus)
|
||||||
|
{
|
||||||
|
switch (exitStatus) {
|
||||||
|
case 0:
|
||||||
|
return StateOK;
|
||||||
|
case 1:
|
||||||
|
return StateWarning;
|
||||||
|
case 2:
|
||||||
|
return StateCritical;
|
||||||
|
default:
|
||||||
|
return StateUnknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -36,6 +36,7 @@ class I2_ICINGA_API NullCheckTask
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Dictionary::Ptr ScriptFunc(const Service::Ptr& service);
|
static Dictionary::Ptr ScriptFunc(const Service::Ptr& service);
|
||||||
|
static ServiceState ExitStatusToState(int exitStatus);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NullCheckTask(void);
|
NullCheckTask(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user