RJ / irccat

IRC bot that simplifies posting to IRC from shell scripts

This URL has Read+Write access

irccat / README
100644 145 lines (101 sloc) 4.331 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
IRCcat
======
 
As in `cat` to IRC.
 
IRCcat does 2 things:
 
1) Listens on a specific ip:port and writes incoming data to an IRC channel.
   This is useful for sending various announcements and log messages to irc
   from shell scripts, Nagios and other services.
 
2) Hands off commands issued on irc to a handler program (eg: shell script)
   and responds to irc with the output of the handler script. This only
   happens for commands addressed to irccat: or prefixed with ?.
   (easily extend irccat functionality with your own scripts)
 
 
Installation
------------
Edit the irccat.xml so it knows which irc server, channel etc..
Check you have sun jvm >=1.5 (java -version)
 
This will build and package irccat as a jar:
 
$ ant dist
 
Then, using the appropriate config file:
 
$ ant -Dconfigfile=./examples/irccat.xml run
 
Also, you'll probably want to install netcat.
 
 
Sending text to IRC
-------------------
By default IRCCat listens on 127.0.0.1:12345, and sends data to the
default (first) channels. In a networked server environment you will p
robably want to make it listen on the private LAN interface.
 
Examples:
 
$ echo "Hello World" | netcat -q0 localhost 12345
$ tail -f /var/log/www/error.log | netcat localhost 12345
 
In a server environment, consider adding a hostname to your internal DNS or
using a virtual IP for irccat to listen on, in case you want to move irccat
to another box later.
 
 
Sending to specific channels
----------------------------
To send to a specific channel rather than the default, put the channel name
as the first word in the data (the channel name will be stripped):
 
$ echo "#mychannel hello world" | netcat -q0 machinename 12345
 
This sends "hello world" to #mychannel
 
First word defines the recipients, you can use comma separated list.
# prefix indicates channel, @ indicates a nick.
 
Examples:
 
- "#chan blah blah"
just sends to #chan
 
- "@RJ psst, this is a pm"
just sends via PM to user RJ
 
- "#channel1,#channel2,@RJ,@Russ blah blah this is the message"
this sends to 2 channels, and 2 users (RJ, Russ)
 
- "#* Attention, something important"
this sends to all channels the bot is in
 
 
Built-in commands
-----------------
There are a handful of built-in commands for instructing the bot at runtime.
 
Built-in commands are prefixed with a !
 
!join #chan pass - joins another channel. pass is optional
!part #chan - parts chan
!channels - lists channels the bot is in
!spam blah blah.. - repeats your message in all joined channels
!exit - System.exit()
 
Trust
-----
 
Any command (?.. !..) uttered in a channel with irccat in is executed and
implicitly trusted.
 
Any command PMed to irccat is ignored unless the user
is joined to the default (first) channel in the config file.
 
 
SVN commit notifications
------------------------
svn hooks let you announce commits etc.
For example, try this in your SVN repo/hooks/post-commit file:
 
REPOS="$1"
REV="$2"
LOG=`/usr/bin/svnlook log -r $REV $REPOS`
AUTHOR=`/usr/bin/svnlook author -r $REV $REPOS`
echo "SVN commit by $AUTHOR (r$REV) '$LOG' http://web-svn-interface.example.com/?rev=$REV" | netcat -q0 machinename 12345
 
 
Nagios alerts to irc
--------------------
Buried in our nagios config is this, from misccommands.cfg:
 
define command {
    command_name host-notify-by-irc
    command_line /bin/echo "#sys Nagios: Host '$HOSTALIAS$' is $HOSTSTATE$ - Info: $OUTPUT$" | /bin/netcat -q 1 irccathost 12345
}
 
define command {
    command_name service-notify-by-irc
    command_line /bin/echo "#sys Nagios: Service $SERVICEDESC$ on '$HOSTALIAS$' is $SERVICESTATE$ - Info: $OUTPUT$" | /bin/netcat -q 1 irccathost 12345
}
 
And in contacts.cfg:
 
define contact{
        contact_name irccat
        alias irccat
        service_notification_period 24x7
        host_notification_period 24x7
        service_notification_options w,c,r
        host_notification_options d,r
        service_notification_commands service-notify-by-irc
        host_notification_commands host-notify-by-irc
        email blah@blah
}
 
Feedback
--------
Email: rj@metabrew.com
Web: http://www.last.fm/user/RJ (work, and the reason irccat exists)
Web: http://www.metabrew.com/ (blog)
Irc: irc://irc.audioscrobbler.com/audioscrobbler