This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Couple of requests/questions

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
P
Philw
Voice
Posts: 7
Joined: Mon Dec 17, 2007 8:42 am

Couple of requests/questions

Post by Philw »

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_Pro ... iew%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
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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: Select all

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?
Last edited by nml375 on Mon Dec 17, 2007 6:26 pm, edited 2 times in total.
NML_375
P
Philw
Voice
Posts: 7
Joined: Mon Dec 17, 2007 8:42 am

Post by Philw »

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.
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Philw: edit your posts and place the code within tags for readability.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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
P
Philw
Voice
Posts: 7
Joined: Mon Dec 17, 2007 8:42 am

Post by Philw »

wow thanks guys working perfectly! :)

Ok, onto the next one of syslog, how possible is that?

Many thanks for your help so far!
P
Philw
Voice
Posts: 7
Joined: Mon Dec 17, 2007 8:42 am

Post by Philw »

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: Select all

           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?
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Code: Select all

putquick "PRIVMSG $channel :\0033$line\003" ;# GREEN 
Need the closing \003 code.. and a semicolon before the comment if its on the same line.
User avatar
YooHoo
Owner
Posts: 939
Joined: Thu Feb 13, 2003 10:07 pm
Location: Redwood Coast

Post by YooHoo »

ppslim wrote a pretty good instructional on this, please take a gander at Colour and Formatting Codes to get a better idea :wink:
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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
Post Reply