Module: check_mk
Branch: master
Commit: e28f764937b73bde4286b87a99cc15e0041c6059
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e28f764937b73b…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Mon Jul 7 16:15:28 2014 +0200
FIX check_mkevents: now able to resolve the hostname of the remote hosts
The check_mkevents plugin was not able to resolve remote hosts, which were specified with
the FQDN.
Conflicts:
ChangeLog
mkeventd/lib/check_mkevents.cc
---
.werks/950 | 9 +++++++++
ChangeLog | 1 +
mkeventd/lib/check_mkevents.cc | 24 ++++++++++++++++++++++--
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/.werks/950 b/.werks/950
new file mode 100644
index 0000000..a56c38c
--- /dev/null
+++ b/.werks/950
@@ -0,0 +1,9 @@
+Title: check_mkevents: now able to resolve the hostname of the remote hosts
+Level: 1
+Component: checks
+Class: fix
+State: unknown
+Version: 1.2.5i5
+Date: 1404742285
+
+The check_mkevents plugin was not able to resolve remote hosts, which were specified with
the FQDN.
diff --git a/ChangeLog b/ChangeLog
index 08679eb..ca4fb27 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -34,6 +34,7 @@
* 1043 FIX: printer_supply: fix value error in default parameters...
* 0626 FIX: veeam_jobs: agent now supports output lines longer than 80 chars
* 1072 FIX: printer_supply: fix colors of Perf-O-Meter on HP OfficeJet...
+ * 0950 FIX: check_mkevents: now able to resolve the hostname of the remote hosts...
Multisite:
* 1013 Sort host names naturally, e.g. foobar11 comes after foobar2...
diff --git a/mkeventd/lib/check_mkevents.cc b/mkeventd/lib/check_mkevents.cc
index 37f0a16..8f1ceb1 100644
--- a/mkeventd/lib/check_mkevents.cc
+++ b/mkeventd/lib/check_mkevents.cc
@@ -33,6 +33,8 @@
#include <unistd.h>
#include <sstream>
#include <vector>
+#include <netdb.h>
+
using namespace std;
#ifndef AF_LOCAL
@@ -48,12 +50,14 @@ void usage()
printf("\n -a do not take into account acknowledged events.\n");
}
+
int main(int argc, char** argv)
{
// Parse arguments
char *host = NULL;
char *remote_host = NULL;
char *remote_hostaddress = NULL;
+ char remote_hostipaddress[64];
int remote_port = 6558;
char *application = NULL;
bool ignore_acknowledged = false;
@@ -96,7 +100,21 @@ int main(int argc, char** argv)
}
if (remote_host) {
+ struct hostent *he;
+ struct in_addr **addr_list;
+
remote_hostaddress = strtok(remote_host, ":");
+ if ( (he = gethostbyname( remote_hostaddress ) ) == NULL)
+ {
+ printf("UNKNOWN - Unable to resolve remote host address: %s\n",
remote_hostaddress);
+ return 3;
+ }
+ addr_list = (struct in_addr **) he->h_addr_list;
+ for(int i = 0; addr_list[i] != NULL; i++)
+ {
+ strcpy(remote_hostipaddress, inet_ntoa(*addr_list[i]) );
+ }
+
char *port_str = strtok(NULL, ":");
if (port_str)
remote_port = atoi(port_str);
@@ -109,17 +127,19 @@ int main(int argc, char** argv)
sock = socket(AF_INET, SOCK_STREAM, 0);
tv.tv_sec = 10;
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (struct timeval *)&tv,
sizeof(struct timeval));
+ // Right now, there is no send timeout..
+ // setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (struct timeval *)&tv,
sizeof(struct timeval));
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
- inet_aton(remote_hostaddress, &addr.sin_addr);
+ inet_aton(remote_hostipaddress, &addr.sin_addr);
addr.sin_port = htons(remote_port);
if (0 > connect(sock, (struct sockaddr*) &addr, sizeof(struct
sockaddr_in)))
{
printf("UNKNOWN - Cannot connect to event daemon via TCP %s:%d
(%s)\n",
- remote_hostaddress, remote_port, strerror(errno));
+ remote_hostipaddress, remote_port, strerror(errno));
exit(3);
}
}