log last request to syylog as well

git-svn-id: http://svn.berlios.de/svnroot/repos/sipsak/trunk@438 75b5f7c7-cfd4-0310-b54c-e118b2c5249a
(cherry picked from commit b90316b5b740e0769847f8c39dd8de62965c22c9)
changes/49/4849/1
nils-ohlmeier 18 years ago committed by Victor Seva
parent 977126da04
commit e7af554183

@ -37,6 +37,14 @@
enum exit_modes exit_mode = EM_DEFAULT;
void log_message(const char *message) {
if ((sysl > 3) && (message != NULL)) {
#ifdef HAVE_SYSLOG
syslog(LOG_INFO, "%s", message);
#endif
}
}
void exit_code(int code, const char *function, const char *reason)
{
#ifdef WITH_TLS_TRANSP

@ -24,6 +24,8 @@ enum exit_modes { EM_DEFAULT, EM_NAGIOS };
extern enum exit_modes exit_mode;
void log_message(const char *message);
void exit_code(int code, const char *function, const char *reason);
#endif

@ -73,6 +73,7 @@ struct sipsak_delay delays;
inline static void on_success(char *rep)
{
log_message(req);
if ((rep != NULL) && re && regexec(re, rep, 0, 0, 0) == REG_NOMATCH) {
fprintf(stderr, "error: RegExp failed\n");
exit_code(32, __PRETTY_FUNCTION__, "regular expression failed");
@ -205,10 +206,12 @@ void trace_reply()
else {
printf("\twithout Contact header\n");
}
if (regexec(&(regexps.okexp), rec, 0, 0, 0) == REG_NOERROR)
if (regexec(&(regexps.okexp), rec, 0, 0, 0) == REG_NOERROR) {
on_success(rec);
else
} else {
log_message(req);
exit_code(1, __PRETTY_FUNCTION__, "received final non-2xx reply");
}
}
}
@ -281,6 +284,7 @@ void handle_default()
on_success(rec);
}
else {
log_message(req);
exit_code(1, __PRETTY_FUNCTION__, "received final non-2xx reply");
}
}
@ -320,6 +324,7 @@ void handle_randtrash()
else {
printf("maximum sendings reached but did not "
"get a response on this request:\n%s\n", req);
log_message(req);
exit_code(3, __PRETTY_FUNCTION__, "missing reply on trashed request");
}
}
@ -364,6 +369,7 @@ void handle_usrloc()
fprintf(stderr, "received:\n%s\nerror: didn't "
"received '200 OK' on register (see "
"above). aborting\n", rec);
log_message(req);
exit_code(1, __PRETTY_FUNCTION__, "received non-2xx reply for REGISTER");
}
if (invite == 0 && message == 0) {
@ -390,7 +396,8 @@ void handle_usrloc()
" retransmitted.\n",
counters.retrans_s_c, delays.retryAfter);
if (counters.retrans_s_c > nagios_warn) {
exit_code(4, __PRETTY_FUNCTION__, "#retransmissions above nagios warn level");
log_message(req);
exit_code(4, __PRETTY_FUNCTION__, "#retransmissions above nagios warn level");
}
}
if (timing) {
@ -449,6 +456,7 @@ void handle_usrloc()
fprintf(stderr, "received:\n%s\nerror: did not "
"received the INVITE that was sent "
"(see above). aborting\n", rec);
log_message(req);
exit_code(1, __PRETTY_FUNCTION__, "did not received our own INVITE request");
}
break;
@ -478,6 +486,7 @@ void handle_usrloc()
"received the '200 OK' that was sent "
"as the reply on the INVITE (see "
"above). aborting\n", rec);
log_message(req);
exit_code(1, __PRETTY_FUNCTION__, "did not received our own 200 reply");
}
break;
@ -528,6 +537,7 @@ void handle_usrloc()
" retransmitted.\n",
counters.retrans_s_c, delays.retryAfter);
if (counters.retrans_s_c > nagios_warn) {
log_message(req);
exit_code(4, __PRETTY_FUNCTION__, "#retransmissions above nagios warn level");
}
}
@ -566,6 +576,7 @@ void handle_usrloc()
"received the 'ACK' that was sent "
"as the reply on the '200 OK' (see "
"above). aborting\n", rec);
log_message(req);
exit_code(1, __PRETTY_FUNCTION__, "missing ACK that was send by myself");
}
break;
@ -590,6 +601,7 @@ void handle_usrloc()
fprintf(stderr, "received:\n%s\nerror: did not "
"received the 'MESSAGE' that was sent "
"(see above). aborting\n", rec);
log_message(req);
exit_code(1, __PRETTY_FUNCTION__, "did not received my own MESSAGE request");
}
break;
@ -638,6 +650,7 @@ void handle_usrloc()
" retransmitted.\n",
counters.retrans_s_c, delays.retryAfter);
if (counters.retrans_s_c > nagios_warn) {
log_message(req);
exit_code(4, __PRETTY_FUNCTION__, "#retransmissions above nagios warn level");
}
}
@ -686,6 +699,7 @@ void handle_usrloc()
"aborting\n", rec);
}
}
log_message(req);
exit_code(1, __PRETTY_FUNCTION__, "received non-2xx reply for MESSAGE request");
}
break;
@ -721,6 +735,7 @@ void handle_usrloc()
"remove bindings request for %s%i (see"
" above). aborting\n", rec, username,
namebeg);
log_message(req);
exit_code(1, __PRETTY_FUNCTION__, "received non-2xx reply for de-register request");
}
break;
@ -1014,6 +1029,7 @@ void shoot(char *buf, int buff_size)
}
fprintf(stderr, "%s\nerror: received 40[17] but cannot "
"authentication without a username or auth username\n", rec);
log_message(req);
exit_code(2, __PRETTY_FUNCTION__, "missing username for authentication");
}
/* prevents a strange error */

@ -542,7 +542,7 @@ int main(int argc, char *argv[])
case 'K':
sysl=str_to_int(0, optarg);
if (sysl < LOG_ALERT || sysl > LOG_DEBUG) {
fprintf(stderr, "error: syslog value '%d' must be between ALERT (1) and DEBUG (7)\n", optarg);
fprintf(stderr, "error: syslog value '%s' must be between ALERT (1) and DEBUG (7)\n", optarg);
exit_code(2, __PRETTY_FUNCTION__, "unsupported syslog value for option K");
}
#ifdef HAVE_SYSLOG_H

@ -724,8 +724,10 @@ void check_socket_error(int socket, int size) {
if (verbose)
printf("\n");
perror("send failure");
if (randtrash == 1)
if (randtrash == 1) {
printf ("last message before send failure:\n%s\n", req);
log_message(req);
}
exit_code(3, __PRETTY_FUNCTION__, "send failure");
}
}
@ -795,6 +797,7 @@ int check_for_message(char *recv, int size, struct sipsak_con_data *cd,
printf("sended the following message three "
"times without getting a response:\n%s\n"
"give up further retransmissions...\n", req);
log_message(req);
exit_code(3, __PRETTY_FUNCTION__, "too many retransmissions, giving up...");
}
else {
@ -809,6 +812,7 @@ int check_for_message(char *recv, int size, struct sipsak_con_data *cd,
if (timing == 0) {
if (verbose>0)
printf("*** giving up, no final response after %.3f ms\n", senddiff);
log_message(req);
exit_code(3, __PRETTY_FUNCTION__, "timeout (no final response)");
}
else {
@ -820,6 +824,7 @@ int check_for_message(char *recv, int size, struct sipsak_con_data *cd,
sd->retryAfter = timer_t1;
if (timing == 0) {
printf("%.3f/%.3f/%.3f ms\n", sd->small_delay, sd->all_delay / count->run, sd->big_delay);
log_message(req);
exit_code(3, __PRETTY_FUNCTION__, "timeout (no final response)");
}
}
@ -1002,6 +1007,7 @@ int recv_message(char *buf, int size, int inv_trans,
#else
printf("\n");
#endif // HAVE_INET_NTOP
log_message(req);
exit_code(3, __PRETTY_FUNCTION__, "received ICMP error");
}
else {
@ -1110,7 +1116,7 @@ int set_target(struct sockaddr_in *adr, unsigned long target, int port, int sock
if (socket != -1) {
if (connect(socket, (struct sockaddr *)adr, sizeof(struct sockaddr_in)) == -1) {
perror("connecting socket failed");
exit_code(2, __PRETTY_FUNCTION__, "connection socket failed");
exit_code(2, __PRETTY_FUNCTION__, "connecting socket failed");
}
#ifdef WITH_TLS_TRANSP
if (transport == SIP_TLS_TRANSPORT) {

Loading…
Cancel
Save