{"id":24,"date":"2008-08-22T14:22:53","date_gmt":"2008-08-22T13:22:53","guid":{"rendered":"http:\/\/lendl.priv.at\/blog\/2008\/08\/22\/rtir-command-line-ticket-creation-autoreply\/"},"modified":"2026-01-26T12:16:54","modified_gmt":"2026-01-26T11:16:54","slug":"rtir-command-line-ticket-creation-autoreply","status":"publish","type":"post","link":"https:\/\/lendl.priv.at\/blog\/2008\/08\/22\/rtir-command-line-ticket-creation-autoreply\/","title":{"rendered":"RT(IR) Command line ticket creation + Autoreply"},"content":{"rendered":"<p>This is one of the &#8220;simple&#8221; problems which always take longer to solve than expected.<\/p>\n<p>The goal: Script <a href=\"http:\/\/www.bestpractical.com\/rtir\/\">RTIR<\/a> to generate Investigations associated with an Incident.<\/p>\n<p>In order to do that, I needed to solve the following who subproblems:<\/p>\n<ol>\n<li> Being able to use the &#8220;edit&#8221; feature in the command line &#8220;rt&#8221; client <strong>and<\/strong> capture the new ticket&#8217;s id<\/li>\n<p>   Basically, I needed to capture the STDOUT of the &#8220;rt&#8221; command, and let also rt invoke vi. My solution:<br \/>\n<code><br \/>\n--- \/usr\/bin\/rt\t2007-10-31 11:52:20.000000000 +0100<br \/>\n+++ \/usr\/local\/bin\/rt\t2008-08-20 14:14:20.000000000 +0200<br \/>\n@@ -1335,7 +1335,7 @@<br \/>\n     local $\/ = undef;<\/p>\n<p>     open(F, \">$file\") || die \"$file: $!\\n\"; print F $text; close(F);<br \/>\n-    system($editor, $file) && die \"Couldn't run $editor.\\n\";<br \/>\n+    system(\"$editor $file < \/dev\/tty > \/dev\/tty\") && die \"Couldn't run $editor.\\n\";<br \/>\n     open(F, $file) || die \"$file: $!\\n\"; $text = <f>; close(F);<br \/>\n     unlink($file);<br \/>\n<\/f><\/code><\/p>\n<li>Add attachments during ticket creation<\/li>\n<p>  The &#8220;Autoreply on Create&#8221; Scrip is supposed to mail out the newly created content to the Requestor, thus   I needed to not only provide plaintext while the creation, but also all the attachments that need to be  sent out to the Requestor.<\/p>\n<p>  Adding text is simple, just use &#8220;Text: foo bar&#8221; to the Template. But attachments are simply not supported for &#8220;rt create&#8221; (and not that easy to add in the code). They are supported for &#8220;rt correspond&#8221;, so I can sidestep the &#8220;attachment on create&#8221; problem by simply splitting up the work into an empty &#8220;rt create&#8221; followed by a &#8220;rt correspond -a file&#8221;.<\/p>\n<p>There is just one gotcha: The Autoreply script will happily mail on ticket creation with an empty mail.<\/p>\n<p>Solution: Change the &#8220;Condition = On Create&#8221; for the Scrip to &#8220;Custom&#8221; with<br \/>\n<code><br \/>\nmy $t = $self->TransactionObj;<br \/>\nreturn 0 unless ($t->Type eq \"Create\");<\/p>\n<p>my $c = $t->ContentObj;<br \/>\nreturn (defined($c)) ? 1 : 0;<br \/>\n<\/code>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This is one of the &#8220;simple&#8221; problems which always take longer to solve than expected. The goal: Script RTIR to generate Investigations associated with an Incident. In order to do that, I needed to solve the following who subproblems: Being able to use the &#8220;edit&#8221; feature in the command line &#8220;rt&#8221; client and capture the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,11],"tags":[],"class_list":["post-24","post","type-post","status-publish","format-standard","hentry","category-cert","category-system-administration"],"_links":{"self":[{"href":"https:\/\/lendl.priv.at\/blog\/wp-json\/wp\/v2\/posts\/24","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lendl.priv.at\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lendl.priv.at\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lendl.priv.at\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lendl.priv.at\/blog\/wp-json\/wp\/v2\/comments?post=24"}],"version-history":[{"count":1,"href":"https:\/\/lendl.priv.at\/blog\/wp-json\/wp\/v2\/posts\/24\/revisions"}],"predecessor-version":[{"id":1042,"href":"https:\/\/lendl.priv.at\/blog\/wp-json\/wp\/v2\/posts\/24\/revisions\/1042"}],"wp:attachment":[{"href":"https:\/\/lendl.priv.at\/blog\/wp-json\/wp\/v2\/media?parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lendl.priv.at\/blog\/wp-json\/wp\/v2\/categories?post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lendl.priv.at\/blog\/wp-json\/wp\/v2\/tags?post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}