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

+ 4
- 0
notify-script.example View File

22
 # Environmental vars that are set by the calling process (tsdecrypt):
22
 # Environmental vars that are set by the calling process (tsdecrypt):
23
 #   _TS             Unix timestamp of the event.
23
 #   _TS             Unix timestamp of the event.
24
 #   _IDENT          tsdecrypt ident (--ident parameter).
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
 #   _MESSAGE_ID     Event message id (For example START, STOP, etc...).
27
 #   _MESSAGE_ID     Event message id (For example START, STOP, etc...).
26
 #   _MESSAGE_TEXT   Event message text. Human readable event message.
28
 #   _MESSAGE_TEXT   Event message text. Human readable event message.
27
 #   _MESSAGE_MSG    Event message id lower cased and "_" is replaced with " "
29
 #   _MESSAGE_MSG    Event message id lower cased and "_" is replaced with " "
60
 		echo "Subject: $EMAIL_SUBJECT_PREFIX ${_IDENT} ${_MESSAGE_MSG}"
62
 		echo "Subject: $EMAIL_SUBJECT_PREFIX ${_IDENT} ${_MESSAGE_MSG}"
61
 		echo "X-IDENT: ${_IDENT}"
63
 		echo "X-IDENT: ${_IDENT}"
62
 		echo "X-MSG-ID: ${_MESSAGE_ID}"
64
 		echo "X-MSG-ID: ${_MESSAGE_ID}"
65
+		echo "X-Input: ${_INPUT_ADDR}"
66
+		echo "X-Output: ${_OUTPUT_ADDR}"
63
 		echo "X-Mailer: tsdecrypt"
67
 		echo "X-Mailer: tsdecrypt"
64
 		echo
68
 		echo
65
 		echo "${_IDENT} ${_MESSAGE_TEXT}"
69
 		echo "${_IDENT} ${_MESSAGE_TEXT}"

+ 19
- 0
notify.c View File

37
 	char	program[512];
37
 	char	program[512];
38
 	char	msg_id[512];
38
 	char	msg_id[512];
39
 	char	text[512];
39
 	char	text[512];
40
+	char	input[128];
41
+	char	output[128];
40
 	int		sync;			/* Wait for message to be delivered */
42
 	int		sync;			/* Wait for message to be delivered */
41
 };
43
 };
42
 
44
 
56
 		char **env = calloc(32, sizeof(char *));
58
 		char **env = calloc(32, sizeof(char *));
57
 		if (asprintf(&env[e++], "_TS=%ld"			, time(NULL)) < 0) exit(EXIT_FAILURE);
59
 		if (asprintf(&env[e++], "_TS=%ld"			, time(NULL)) < 0) exit(EXIT_FAILURE);
58
 		if (asprintf(&env[e++], "_IDENT=%s"			, shared->ident) < 0) exit(EXIT_FAILURE);
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
 		if (asprintf(&env[e++], "_MESSAGE_ID=%s"	, shared->msg_id) < 0) exit(EXIT_FAILURE);
63
 		if (asprintf(&env[e++], "_MESSAGE_ID=%s"	, shared->msg_id) < 0) exit(EXIT_FAILURE);
60
 		if (asprintf(&env[e++], "_MESSAGE_TEXT=%s"	, shared->text) < 0) exit(EXIT_FAILURE);
64
 		if (asprintf(&env[e++], "_MESSAGE_TEXT=%s"	, shared->text) < 0) exit(EXIT_FAILURE);
61
 		r = strlen(shared->msg_id);
65
 		r = strlen(shared->msg_id);
153
 	strncpy(np->text, msg_text, sizeof(np->text) - 1);
157
 	strncpy(np->text, msg_text, sizeof(np->text) - 1);
154
 	np->text[sizeof(np->text) - 1] = 0;
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
 	queue_add(ts->notify->notifications, np);
175
 	queue_add(ts->notify->notifications, np);
157
 }
176
 }
158
 
177
 

+ 2
- 0
tsdecrypt.1 View File

340
 
340
 
341
   \fB_TS\fR             Unix timestamp of the event.
341
   \fB_TS\fR             Unix timestamp of the event.
342
   \fB_IDENT\fR          tsdecrypt ident parameter with "/" replaced by "\-".
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
   \fB_MESSAGE_ID\fR     Event message id (for example START, STOP, etc...).
345
   \fB_MESSAGE_ID\fR     Event message id (for example START, STOP, etc...).
344
   \fB_MESSAGE_MSG\fR    Event message id with "_" replaced by " ".
346
   \fB_MESSAGE_MSG\fR    Event message id with "_" replaced by " ".
345
   \fB_MESSAGE_TEXT\fR   Event message text. Human readable event message.
347
   \fB_MESSAGE_TEXT\fR   Event message text. Human readable event message.

Loading…
Cancel
Save