| View previous topic :: View next topic |
| Author |
Message |
Philw Voice
Joined: 17 Dec 2007 Posts: 7
|
Posted: Mon Dec 17, 2007 8:49 am Post subject: Couple of requests/questions |
|
|
Hi all
I have a monitoring system setup for our network, currently I have an irc bot written in python that alerts us when there are problems. In essence all it does it check a file and whenever it finds info in there it outputs it to the channel.
How can this be achieved on tcl? (I'm a complete noivce) or is it possible to run a python script on an eggdrop? I'm just trying to get everything onto one bot so we don't have hundreds of bots in a channel.
The current bot is located here http://www.nagiosexchange.org/AddOn_Projects.22.0.html?&tx_netnagext_pi1%5Bp_view%5D=757
I'm sure its pretty simple, just a case of timers? I have tried but my efforts failed
putlog "Nagios IRC BOT Script"
set MyPipe "/usr/local/nagios/etc/objects/scripts/ircbot/ircpipe"
set x 1
while {$x < 5} {
set f [open $MyPipe]
foreach line [split [read $f \n]] {
if {!$line == ""} { putserv PRIVMSG #channel $line}
}
}
The pipe is a FIFO.
Also as another question, I wondered if anyone knew of a syslog eggdrop script, that could receive syslog info from devices and output it straight to the channel? If not how simple would this be to achieve?
Hope someone can help |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Mon Dec 17, 2007 9:56 am Post subject: |
|
|
Reading from a fifo is abit more complicated, as you need an event-driven process to read data as it becomes available on the file interface.
The following code should point you in the right direction:
| Code: | proc readfifo {file} {
if {[gets $file text] < 0} {
if {[eof $file]} {
close $file
putlog "FIFO closed due to eof-condition!"
return
}
} {
puthelp "PRIVMSG #yourchannel :$text"
}
}
set fid [open "/path/to/fifo" "RDWR"]
fconfigure $fid -blocking 0
fileevent $fid readable [list readfifo $fid]
|
As for implementing syslog, would you like your eggdrop to act as a syslog daemon, or simply recieve messages from the system syslogd? _________________ NML_375, idling at #eggdrop@IrcNET
Last edited by nml375 on Mon Dec 17, 2007 6:26 pm; edited 2 times in total |
|
| Back to top |
|
 |
Philw Voice
Joined: 17 Dec 2007 Posts: 7
|
Posted: Mon Dec 17, 2007 11:24 am Post subject: |
|
|
Hi
Thanks for the prompt reply!
putlog "Nagios IRC BOT Script"
set file "/usr/local/nagios/etc/objects/scripts/ircbot/ircpipe"
proc readfifo {file} {
if {[gets $file text] < 0} {
if {[eof $file]} {
close $file
putlog "FIFO closed due to eof-condition!"
return
}
} {
puthelp "PRIVMSG #chan :$line"
}
}
set fid [open "/usr/local/nagios/etc/objects/scripts/ircbot/ircpipe" "RDONLY"]
fconfigure $fid -blocking 0
fileevent $fid readable [list readfifo $fid]
I did that, (sorry like i said im a novice) but the bot hangs on startup, not doing anything, any ideas?
With regards to the syslog, it needs to act as a daemon, receiving messages from network devices. |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Mon Dec 17, 2007 5:38 pm Post subject: |
|
|
Philw: edit your posts and place the code within [code][/code] tags for readability. _________________ Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Mon Dec 17, 2007 6:25 pm Post subject: |
|
|
Oops, minor mistake...
change $line to $text, mixed variable names while coding..
Updating my previous post in a moment..
Also opened the file as readonly, which will cause it to block until another process opens it as writeonly... changed to read-write access, and it should'nt block anymore now. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
Philw Voice
Joined: 17 Dec 2007 Posts: 7
|
Posted: Tue Dec 18, 2007 8:26 am Post subject: |
|
|
wow thanks guys working perfectly!
Ok, onto the next one of syslog, how possible is that?
Many thanks for your help so far! |
|
| Back to top |
|
 |
Philw Voice
Joined: 17 Dec 2007 Posts: 7
|
Posted: Tue Dec 18, 2007 7:08 pm Post subject: |
|
|
Hi Back again
Maybe im doing something wrong here, but
Ive got the script working, bu im just trying to do a bit of color coding on mirc with some if statements. Thing is when I put my code in the bot doesnt seem to output anything, i see nothign in the log or channel. However when this code is out it works fine. What have I done wrong?
| Code: |
if {[string match {*RECOVERY*} $line]} {
putquick "PRIVMSG $channel :\0033$line" # GREEN
} elseif {[string match {*PROBLEM*} $line]} {
putquick "PRIVMSG $channel :\0034$line" # RED
} else {
putquick "PRIVMSG $channel :$line"
}
|
Can anyone spot what's wrong with this? |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Dec 18, 2007 7:24 pm Post subject: |
|
|
| Code: | | putquick "PRIVMSG $channel :\0033$line\003" ;# GREEN |
Need the closing \003 code.. and a semicolon before the comment if its on the same line. |
|
| Back to top |
|
 |
YooHoo Owner

Joined: 13 Feb 2003 Posts: 939 Location: Redwood Coast
|
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Dec 19, 2007 12:42 pm Post subject: |
|
|
I'm not sure if your indenting is simply off, but have you checked that all { and } match up?
As for the terminating \003, it's recommended, but not mandatory for most irc clients. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
|