mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-28 08:04:14 +02:00
compatido: replace gettimeofday with Utility::GetTime()
* fixes build on windows * only timestamp (4) of idomod requires seconds.useconds as output, which needs proper formatting within a stringstream - std::precision(17) is required. * all other timestamps are just unix seconds, so we require static casts to integer here
This commit is contained in:
parent
edc2d74a70
commit
faf741e3b9
@ -132,8 +132,7 @@ void CompatIdoComponent::OpenSink(String node, String service)
|
|||||||
*/
|
*/
|
||||||
void CompatIdoComponent::SendHello(String instancename)
|
void CompatIdoComponent::SendHello(String instancename)
|
||||||
{
|
{
|
||||||
time_t now;
|
time_t now = static_cast<int>(Utility::GetTime());
|
||||||
time(&now);
|
|
||||||
|
|
||||||
/* connection is always TCP */
|
/* connection is always TCP */
|
||||||
/* connecttype is always initial */
|
/* connecttype is always initial */
|
||||||
@ -184,15 +183,12 @@ void CompatIdoComponent::CloseSink(void)
|
|||||||
*/
|
*/
|
||||||
void CompatIdoComponent::StartConfigDump(void)
|
void CompatIdoComponent::StartConfigDump(void)
|
||||||
{
|
{
|
||||||
struct timeval now;
|
|
||||||
gettimeofday(&now, NULL);
|
|
||||||
|
|
||||||
/* configtype =1 (original), =2 (retained == default) */
|
/* configtype =1 (original), =2 (retained == default) */
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "\n\n"
|
message << "\n\n"
|
||||||
<< 900 << ":" << "\n" /* startconfigdump */
|
<< 900 << ":" << "\n" /* startconfigdump */
|
||||||
<< 245 << "=" << "RETAINED" << "\n" /* configdumptype */
|
<< 245 << "=" << "RETAINED" << "\n" /* configdumptype */
|
||||||
<< 4 << "=" << now.tv_sec << "." << now.tv_usec << "\n" /* timestamp */
|
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
|
||||||
<< 999 /* enddata */
|
<< 999 /* enddata */
|
||||||
<< "\n\n";
|
<< "\n\n";
|
||||||
|
|
||||||
@ -204,13 +200,10 @@ void CompatIdoComponent::StartConfigDump(void)
|
|||||||
*/
|
*/
|
||||||
void CompatIdoComponent::EndConfigDump(void)
|
void CompatIdoComponent::EndConfigDump(void)
|
||||||
{
|
{
|
||||||
struct timeval now;
|
|
||||||
gettimeofday(&now, NULL);
|
|
||||||
|
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "\n\n"
|
message << "\n\n"
|
||||||
<< 901 << ":" << "\n" /* endconfigdump */
|
<< 901 << ":" << "\n" /* endconfigdump */
|
||||||
<< 4 << "=" << now.tv_sec << "." << now.tv_usec << "\n" /* timestamp */
|
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
|
||||||
<< 999 /* enddata */
|
<< 999 /* enddata */
|
||||||
<< "\n\n";
|
<< "\n\n";
|
||||||
|
|
||||||
@ -224,13 +217,10 @@ void CompatIdoComponent::EndConfigDump(void)
|
|||||||
*/
|
*/
|
||||||
void CompatIdoComponent::DumpHostObject(const Host::Ptr& host)
|
void CompatIdoComponent::DumpHostObject(const Host::Ptr& host)
|
||||||
{
|
{
|
||||||
struct timeval now;
|
|
||||||
gettimeofday(&now, NULL);
|
|
||||||
|
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "\n"
|
message << "\n"
|
||||||
<< 400 << ":" << "\n" /* hostdefinition */
|
<< 400 << ":" << "\n" /* hostdefinition */
|
||||||
<< 4 << "=" << now.tv_sec << "." << now.tv_usec << "\n" /* timestamp */
|
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
|
||||||
<< 174 << "=" << host->GetName() << "\n" /* hostname */
|
<< 174 << "=" << host->GetName() << "\n" /* hostname */
|
||||||
<< 258 << "=" << host->GetAlias() << "\n" /* displayname */
|
<< 258 << "=" << host->GetAlias() << "\n" /* displayname */
|
||||||
<< 159 << "=" << host->GetAlias() << "\n" /* hostalias */
|
<< 159 << "=" << host->GetAlias() << "\n" /* hostalias */
|
||||||
@ -314,16 +304,13 @@ void CompatIdoComponent::DumpHostStatus(const Host::Ptr& host)
|
|||||||
else
|
else
|
||||||
state = 0; /* up */
|
state = 0; /* up */
|
||||||
|
|
||||||
struct timeval now;
|
|
||||||
gettimeofday(&now, NULL);
|
|
||||||
|
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "\n"
|
message << "\n"
|
||||||
<< 212 << ":" << "\n" /* hoststatusdata */
|
<< 212 << ":" << "\n" /* hoststatusdata */
|
||||||
<< 1 << "=" << "" << "\n" /* type */
|
<< 1 << "=" << "" << "\n" /* type */
|
||||||
<< 2 << "=" << "" << "\n" /* flags */
|
<< 2 << "=" << "" << "\n" /* flags */
|
||||||
<< 3 << "=" << "" << "\n" /* attributes */
|
<< 3 << "=" << "" << "\n" /* attributes */
|
||||||
<< 4 << "=" << now.tv_sec << "." << now.tv_usec << "\n" /* timestamp */
|
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
|
||||||
<< 53 << "=" << host->GetName() << "\n" /* host */
|
<< 53 << "=" << host->GetName() << "\n" /* host */
|
||||||
<< 95 << "=" << "" << "\n" /* output */
|
<< 95 << "=" << "" << "\n" /* output */
|
||||||
<< 125 << "=" << "" << "\n" /* longout */
|
<< 125 << "=" << "" << "\n" /* longout */
|
||||||
@ -333,8 +320,8 @@ void CompatIdoComponent::DumpHostStatus(const Host::Ptr& host)
|
|||||||
<< 115 << "=" << 1 << "\n" /* shouldbescheduled */
|
<< 115 << "=" << 1 << "\n" /* shouldbescheduled */
|
||||||
<< 25 << "=" << 1 << "\n" /* currentcheckattempt */
|
<< 25 << "=" << 1 << "\n" /* currentcheckattempt */
|
||||||
<< 76 << "=" << 1 << "\n" /* maxcheckattempts */
|
<< 76 << "=" << 1 << "\n" /* maxcheckattempts */
|
||||||
<< 58 << "=" << Utility::GetTime() << "\n" /* lasthostcheck */
|
<< 58 << "=" << static_cast<int>(Utility::GetTime()) << "\n" /* lasthostcheck (seconds only) */
|
||||||
<< 81 << "=" << Utility::GetTime() << "\n" /* nexthostcheck */
|
<< 81 << "=" << static_cast<int>(Utility::GetTime()) << "\n" /* nexthostcheck (seconds only) */
|
||||||
<< 12 << "=" << "" << "\n" /* checktype */
|
<< 12 << "=" << "" << "\n" /* checktype */
|
||||||
<< 63 << "=" << "" << "\n" /* laststatechange */
|
<< 63 << "=" << "" << "\n" /* laststatechange */
|
||||||
<< 57 << "=" << "" << "\n" /* lasthardstatechange */
|
<< 57 << "=" << "" << "\n" /* lasthardstatechange */
|
||||||
@ -382,13 +369,10 @@ void CompatIdoComponent::DumpHostStatus(const Host::Ptr& host)
|
|||||||
*/
|
*/
|
||||||
void CompatIdoComponent::DumpServiceObject(const Service::Ptr& service)
|
void CompatIdoComponent::DumpServiceObject(const Service::Ptr& service)
|
||||||
{
|
{
|
||||||
struct timeval now;
|
|
||||||
gettimeofday(&now, NULL);
|
|
||||||
|
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "\n"
|
message << "\n"
|
||||||
<< 402 << ":" << "\n" /* servicedefinition */
|
<< 402 << ":" << "\n" /* servicedefinition */
|
||||||
<< 4 << "=" << now.tv_sec << "." << now.tv_usec << "\n" /* timestamp */
|
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
|
||||||
<< 174 << "=" << service->GetHost()->GetName() << "\n" /* hostname */
|
<< 174 << "=" << service->GetHost()->GetName() << "\n" /* hostname */
|
||||||
<< 258 << "=" << service->GetAlias() << "\n" /* displayname */
|
<< 258 << "=" << service->GetAlias() << "\n" /* displayname */
|
||||||
<< 210 << "=" << service->GetAlias() << "\n" /* servicedescription */
|
<< 210 << "=" << service->GetAlias() << "\n" /* servicedescription */
|
||||||
@ -479,16 +463,13 @@ void CompatIdoComponent::DumpServiceStatus(const Service::Ptr& service)
|
|||||||
if (state > StateUnknown)
|
if (state > StateUnknown)
|
||||||
state = StateUnknown;
|
state = StateUnknown;
|
||||||
|
|
||||||
struct timeval now;
|
|
||||||
gettimeofday(&now, NULL);
|
|
||||||
|
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "\n"
|
message << "\n"
|
||||||
<< 213 << ":" << "\n" /* servicestatusdata */
|
<< 213 << ":" << "\n" /* servicestatusdata */
|
||||||
<< 1 << "=" << "" << "\n" /* type */
|
<< 1 << "=" << "" << "\n" /* type */
|
||||||
<< 2 << "=" << "" << "\n" /* flags */
|
<< 2 << "=" << "" << "\n" /* flags */
|
||||||
<< 3 << "=" << "" << "\n" /* attributes */
|
<< 3 << "=" << "" << "\n" /* attributes */
|
||||||
<< 4 << "=" << now.tv_sec << "." << now.tv_usec << "\n" /* timestamp */
|
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
|
||||||
<< 53 << "=" << service->GetHost()->GetName() << "\n" /* host */
|
<< 53 << "=" << service->GetHost()->GetName() << "\n" /* host */
|
||||||
<< 114 << "=" << service->GetAlias() << "\n" /* service */
|
<< 114 << "=" << service->GetAlias() << "\n" /* service */
|
||||||
<< 95 << "=" << output << "\n" /* output */
|
<< 95 << "=" << output << "\n" /* output */
|
||||||
@ -499,11 +480,11 @@ void CompatIdoComponent::DumpServiceStatus(const Service::Ptr& service)
|
|||||||
<< 115 << "=" << "1" << "\n" /* shouldbescheduled */
|
<< 115 << "=" << "1" << "\n" /* shouldbescheduled */
|
||||||
<< 25 << "=" << service->GetCurrentCheckAttempt() << "\n" /* currentcheckattempt */
|
<< 25 << "=" << service->GetCurrentCheckAttempt() << "\n" /* currentcheckattempt */
|
||||||
<< 76 << "=" << service->GetMaxCheckAttempts() << "\n" /* maxcheckattempts */
|
<< 76 << "=" << service->GetMaxCheckAttempts() << "\n" /* maxcheckattempts */
|
||||||
<< 61 << "=" << schedule_end << "\n" /* lastservicecheck */
|
<< 61 << "=" << static_cast<int>(schedule_end) << "\n" /* lastservicecheck (seconds only) */
|
||||||
<< 83 << "=" << service->GetNextCheck() << "\n" /* nextservicecheck */
|
<< 83 << "=" << static_cast<int>(service->GetNextCheck()) << "\n" /* nextservicecheck (seconds only) */
|
||||||
<< 12 << "=" << "" << "\n" /* checktype */
|
<< 12 << "=" << "" << "\n" /* checktype */
|
||||||
<< 63 << "=" << service->GetLastStateChange() << "\n" /* laststatechange */
|
<< 63 << "=" << static_cast<int>(service->GetLastStateChange()) << "\n" /* laststatechange (seconds only) */
|
||||||
<< 57 << "=" << service->GetLastHardStateChange() << "\n" /* lasthardstatechange */
|
<< 57 << "=" << static_cast<int>(service->GetLastHardStateChange()) << "\n" /* lasthardstatechange (seconds only) */
|
||||||
<< 56 << "=" << "" << "\n" /* lasthardstate */
|
<< 56 << "=" << "" << "\n" /* lasthardstate */
|
||||||
<< 66 << "=" << "" << "\n" /* lasttimeok */
|
<< 66 << "=" << "" << "\n" /* lasttimeok */
|
||||||
<< 70 << "=" << "" << "\n" /* lasttimewarning */
|
<< 70 << "=" << "" << "\n" /* lasttimewarning */
|
||||||
@ -548,9 +529,6 @@ void CompatIdoComponent::DumpServiceStatus(const Service::Ptr& service)
|
|||||||
*/
|
*/
|
||||||
void CompatIdoComponent::DumpProgramStatusData(void)
|
void CompatIdoComponent::DumpProgramStatusData(void)
|
||||||
{
|
{
|
||||||
struct timeval now;
|
|
||||||
gettimeofday(&now, NULL);
|
|
||||||
|
|
||||||
double start_time = IcingaApplication::GetInstance()->GetStartTime();
|
double start_time = IcingaApplication::GetInstance()->GetStartTime();
|
||||||
|
|
||||||
stringstream message;
|
stringstream message;
|
||||||
@ -559,7 +537,7 @@ void CompatIdoComponent::DumpProgramStatusData(void)
|
|||||||
<< 1 << "=" << "" << "\n" /* type */
|
<< 1 << "=" << "" << "\n" /* type */
|
||||||
<< 2 << "=" << "" << "\n" /* flags */
|
<< 2 << "=" << "" << "\n" /* flags */
|
||||||
<< 3 << "=" << "" << "\n" /* attributes */
|
<< 3 << "=" << "" << "\n" /* attributes */
|
||||||
<< 4 << "=" << now.tv_sec << "." << now.tv_usec << "\n" /* timestamp */
|
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
|
||||||
<< 106 << "=" << static_cast<int>(start_time) << "\n" /* programstarttime */
|
<< 106 << "=" << static_cast<int>(start_time) << "\n" /* programstarttime */
|
||||||
<< 102 << "=" << Utility::GetPid() << "\n" /* processid */
|
<< 102 << "=" << Utility::GetPid() << "\n" /* processid */
|
||||||
<< 28 << "=" << "1" << "\n" /* daemonmode */
|
<< 28 << "=" << "1" << "\n" /* daemonmode */
|
||||||
@ -629,13 +607,10 @@ void CompatIdoComponent::DumpConfigObjects(void)
|
|||||||
HostGroup::Ptr hg = HostGroup::GetByName(name);
|
HostGroup::Ptr hg = HostGroup::GetByName(name);
|
||||||
|
|
||||||
/* dump the hostgroup and its attributes/members to ido */
|
/* dump the hostgroup and its attributes/members to ido */
|
||||||
struct timeval now;
|
|
||||||
gettimeofday(&now, NULL);
|
|
||||||
|
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "\n"
|
message << "\n"
|
||||||
<< 401 << ":" << "\n" /* hostgroupdefinition */
|
<< 401 << ":" << "\n" /* hostgroupdefinition */
|
||||||
<< 4 << "=" << now.tv_sec << "." << now.tv_usec << "\n" /* timestamp */
|
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
|
||||||
<< 172 << "=" << name << "\n" /* hostgroupname */
|
<< 172 << "=" << name << "\n" /* hostgroupname */
|
||||||
<< 170 << "=" << hg->GetAlias() << "\n"; /* hostgroupalias */
|
<< 170 << "=" << hg->GetAlias() << "\n"; /* hostgroupalias */
|
||||||
|
|
||||||
@ -676,13 +651,10 @@ void CompatIdoComponent::DumpConfigObjects(void)
|
|||||||
ServiceGroup::Ptr sg = ServiceGroup::GetByName(name);
|
ServiceGroup::Ptr sg = ServiceGroup::GetByName(name);
|
||||||
|
|
||||||
/* dump the servicegroup and its attributes/members to ido */
|
/* dump the servicegroup and its attributes/members to ido */
|
||||||
struct timeval now;
|
|
||||||
gettimeofday(&now, NULL);
|
|
||||||
|
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "\n"
|
message << "\n"
|
||||||
<< 403 << ":" << "\n" /* servicegroupdefinition */
|
<< 403 << ":" << "\n" /* servicegroupdefinition */
|
||||||
<< 4 << "=" << now.tv_sec << "." << now.tv_usec << "\n" /* timestamp */
|
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
|
||||||
<< 220 << "=" << name << "\n" /* servicegroupname */
|
<< 220 << "=" << name << "\n" /* servicegroupname */
|
||||||
<< 218 << "=" << sg->GetAlias() << "\n"; /* servicegroupalias */
|
<< 218 << "=" << sg->GetAlias() << "\n"; /* servicegroupalias */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user