Module: check_mk
Branch: master
Commit: e14e3d615197ae0e3dec17b8325d948e6a488d0b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e14e3d615197ae…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Oct 18 12:46:12 2013 +0200
mkeventd: Fixed Makefile. Improved error handling, fixed unixsocket connection
---
mkeventd/lib/Makefile | 2 +-
mkeventd/lib/check_mkevents.cc | 32 ++++++++++++++++++++++++--------
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/mkeventd/lib/Makefile b/mkeventd/lib/Makefile
index 3a9e735..fc6cfd7 100644
--- a/mkeventd/lib/Makefile
+++ b/mkeventd/lib/Makefile
@@ -24,7 +24,7 @@
all: check_mkevents_c
-check_mkevents_c:
+check_mkevents_c: check_mkevents.cc
g++ -O2 -o check_mkevents_c check_mkevents.cc
clean:
diff --git a/mkeventd/lib/check_mkevents.cc b/mkeventd/lib/check_mkevents.cc
index 0e5415d..ca4b769 100644
--- a/mkeventd/lib/check_mkevents.cc
+++ b/mkeventd/lib/check_mkevents.cc
@@ -42,6 +42,12 @@ using namespace std;
#define PF_LOCAL PF_UNIX
#endif
+void usage()
+{
+ printf("Usage: check_mkevents_c [-H REMOTE:PORT] [-a] HOST
[APPLICATION]");
+ printf("\n -a do not take into account acknowledged events.\n");
+}
+
int main(int argc, char** argv)
{
// Parse arguments
@@ -72,6 +78,11 @@ int main(int argc, char** argv)
}
}
+ if (!host) {
+ usage();
+ exit(3);
+ }
+
// Get omd environment
char *omd_path = getenv("OMD_ROOT");
char unixsocket_path[1024];
@@ -104,23 +115,28 @@ int main(int argc, char** argv)
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\n",
- remote_hostaddress, remote_port);
+ printf("UNKNOWN - Cannot connect to event daemon via TCP %s:%d
(%s)\n",
+ remote_hostaddress, remote_port, strerror(errno));
exit(3);
}
} else {
- sock = socket(AF_UNIX, SOCK_STREAM , 0);
+ sock = socket(PF_LOCAL, SOCK_STREAM , 0);
+ if (sock < 0) {
+ printf("UNKNOWN - Cannot create client socket: %s\n",
strerror(errno));
+ exit(3);
+ }
+
tv.tv_sec = 3;
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (struct timeval *)&tv,
sizeof(struct timeval));
struct sockaddr_un addr;
memset(&addr, 0, sizeof(struct sockaddr_un));
- addr.sun_family = AF_UNIX;
- strncpy(addr.sun_path, unixsocket_path, sizeof(addr.sun_path)-1);
+ addr.sun_family = AF_LOCAL;
+ strncpy(addr.sun_path, unixsocket_path, sizeof(addr.sun_path));
- if(0 > connect(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr))){
- printf("UNKNOWN - Cannot connect to event daemon via UNIX socket
%s\n",
- unixsocket_path);
+ if(0 > connect(sock, (struct sockaddr*) &addr, sizeof(struct
sockaddr_un))){
+ printf("UNKNOWN - Cannot connect to event daemon via UNIX socket %s
(%s)\n",
+ unixsocket_path, strerror(errno));
exit(3);
}
}