Browse Source

Start passing _INPUT_ADDR and _OUTPUT_ADDR variables to notify script.

Georgi Chorbadzhiyski 7 years ago
parent
commit
e6fbc81d83
4 changed files with 26 additions and 0 deletions
  1. 1
    0
      ChangeLog
  2. 4
    0
      notify-script.example
  3. 19
    0
      notify.c
  4. 2
    0
      tsdecrypt.1

+ 1
- 0
ChangeLog View File

@@ -4,6 +4,7 @@ xxxx-xx-xx : Version -next
4 4
  * Add --notify-wait (-9) option (not set by default). Using it prevents
5 5
    running of several notification scripts in parallel which can lead to
6 6
    races if the scripts are used for logging.
7
+ * Start passing _INPUT_ADDR and _OUTPUT_ADDR variables to notify script.
7 8
 
8 9
 2013-09-12 : Version 10.0
9 10
  * Add --ecm-only (-v) option. This allows processing of ECMs but without

+ 4
- 0
notify-script.example View File

@@ -22,6 +22,8 @@ LOG_FILE="$LOGDIR/notify.${_IDENT}.notify.log"
22 22
 # Environmental vars that are set by the calling process (tsdecrypt):
23 23
 #   _TS             Unix timestamp of the event.
24 24
 #   _IDENT          tsdecrypt ident (--ident parameter).
25
+#   _INPUT_ADDR     Input address and port (for example 239.1.2.3:5000).
26
+#   _OUTPUT_ADDR    Output address and port (for example 239.9.8.7:5000).
25 27
 #   _MESSAGE_ID     Event message id (For example START, STOP, etc...).
26 28
 #   _MESSAGE_TEXT   Event message text. Human readable event message.
27 29
 #   _MESSAGE_MSG    Event message id lower cased and "_" is replaced with " "
@@ -60,6 +62,8 @@ then
60 62
 		echo "Subject: $EMAIL_SUBJECT_PREFIX ${_IDENT} ${_MESSAGE_MSG}"
61 63
 		echo "X-IDENT: ${_IDENT}"
62 64
 		echo "X-MSG-ID: ${_MESSAGE_ID}"
65
+		echo "X-Input: ${_INPUT_ADDR}"
66
+		echo "X-Output: ${_OUTPUT_ADDR}"
63 67
 		echo "X-Mailer: tsdecrypt"
64 68
 		echo
65 69
 		echo "${_IDENT} ${_MESSAGE_TEXT}"

+ 19
- 0
notify.c View File

@@ -37,6 +37,8 @@ struct npriv {
37 37
 	char	program[512];
38 38
 	char	msg_id[512];
39 39
 	char	text[512];
40
+	char	input[128];
41
+	char	output[128];
40 42
 	int		sync;			/* Wait for message to be delivered */
41 43
 };
42 44
 
@@ -56,6 +58,8 @@ static void *do_notify(void *in) {
56 58
 		char **env = calloc(32, sizeof(char *));
57 59
 		if (asprintf(&env[e++], "_TS=%ld"			, time(NULL)) < 0) exit(EXIT_FAILURE);
58 60
 		if (asprintf(&env[e++], "_IDENT=%s"			, shared->ident) < 0) exit(EXIT_FAILURE);
61
+		if (asprintf(&env[e++], "_INPUT_ADDR=%s"	, shared->input) < 0) exit(EXIT_FAILURE);
62
+		if (asprintf(&env[e++], "_OUTPUT_ADDR=%s"	, shared->output) < 0) exit(EXIT_FAILURE);
59 63
 		if (asprintf(&env[e++], "_MESSAGE_ID=%s"	, shared->msg_id) < 0) exit(EXIT_FAILURE);
60 64
 		if (asprintf(&env[e++], "_MESSAGE_TEXT=%s"	, shared->text) < 0) exit(EXIT_FAILURE);
61 65
 		r = strlen(shared->msg_id);
@@ -153,6 +157,21 @@ static void notify_func(struct ts *ts, int sync_msg, char *msg_id, char *msg_tex
153 157
 	strncpy(np->text, msg_text, sizeof(np->text) - 1);
154 158
 	np->text[sizeof(np->text) - 1] = 0;
155 159
 
160
+	if (ts->input.type == NET_IO) {
161
+		snprintf(np->input, sizeof(np->input), "%s:%s", ts->input.hostname, ts->input.service);
162
+	} else if (ts->input.type == FILE_IO) {
163
+		snprintf(np->input, sizeof(np->input), "%s", ts->input.fd == 0 ? "STDIN" : "FILE");
164
+	}
165
+	if (ts->output_stream) {
166
+		if (ts->output.type == NET_IO) {
167
+			snprintf(np->output, sizeof(np->output), "%s:%s", ts->output.hostname, ts->output.service);
168
+		} else if (ts->output.type == FILE_IO) {
169
+			snprintf(np->output, sizeof(np->output), "%s", ts->output.fd == 1 ? "STDOUT" : "FILE");
170
+		}
171
+	} else {
172
+		snprintf(np->output, sizeof(np->output), "DISABLED");
173
+	}
174
+
156 175
 	queue_add(ts->notify->notifications, np);
157 176
 }
158 177
 

+ 2
- 0
tsdecrypt.1 View File

@@ -340,6 +340,8 @@ before executing the external notification program. The variables are:
340 340
 
341 341
   \fB_TS\fR             Unix timestamp of the event.
342 342
   \fB_IDENT\fR          tsdecrypt ident parameter with "/" replaced by "\-".
343
+  \fB_INPUT_ADDR\fR     Input address and port (for example 239.1.2.3:5000)
344
+  \fB_OUTPUT_ADDR\fR    Output address and port (for example 239.9.8.7:5000)
343 345
   \fB_MESSAGE_ID\fR     Event message id (for example START, STOP, etc...).
344 346
   \fB_MESSAGE_MSG\fR    Event message id with "_" replaced by " ".
345 347
   \fB_MESSAGE_TEXT\fR   Event message text. Human readable event message.

Loading…
Cancel
Save