egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Couple of requests/questions

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Philw
Voice


Joined: 17 Dec 2007
Posts: 7

PostPosted: Mon Dec 17, 2007 8:49 am    Post subject: Couple of requests/questions Reply with quote

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
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Dec 17, 2007 9:56 am    Post subject: Reply with quote

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
View user's profile Send private message
Philw
Voice


Joined: 17 Dec 2007
Posts: 7

PostPosted: Mon Dec 17, 2007 11:24 am    Post subject: Reply with quote

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
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Mon Dec 17, 2007 5:38 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Dec 17, 2007 6:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
Philw
Voice


Joined: 17 Dec 2007
Posts: 7

PostPosted: Tue Dec 18, 2007 8:26 am    Post subject: Reply with quote

wow thanks guys working perfectly! Smile

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

Many thanks for your help so far!
Back to top
View user's profile Send private message
Philw
Voice


Joined: 17 Dec 2007
Posts: 7

PostPosted: Tue Dec 18, 2007 7:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Tue Dec 18, 2007 7:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
YooHoo
Owner


Joined: 13 Feb 2003
Posts: 939
Location: Redwood Coast

PostPosted: Wed Dec 19, 2007 1:52 am    Post subject: Reply with quote

ppslim wrote a pretty good instructional on this, please take a gander at Colour and Formatting Codes to get a better idea Wink
_________________
Mr. Green
Johoho's TCL for beginners
Mr. Green
Back to top
View user's profile Send private message Send e-mail
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Dec 19, 2007 12:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber