| View previous topic :: View next topic |
| Author |
Message |
freelance Voice
Joined: 23 Dec 2013 Posts: 12
|
Posted: Mon Dec 23, 2013 7:02 pm Post subject: website up or down status |
|
|
I did a search on here and went through 70+ pages and only found one post close to what I am looking for. Maybe this could be modified to fit my needs?
Posted by Dragnlord in 2008
| Code: | # Usage example: !sitetest egghelp.org
bind pub - !sitetest site:test
proc site:test {n u h c a} {
if {[catch {set site_test [socket -async $a 80]} sockerr]} {
putserv "privmsg $c :$a is Down"
} else {
putserv "privmsg $c :$a is Up"
}
if {[info exist site_test]} {close $site_test}
}
putlog "Site Test loaded.." |
These are my needs. I have a list of servers that we need to periodically check to make sure they are up. Below is how I would like it to print out. ltc-us is one ip and ltc-eu is a seperate ip.
<user>!status ltc-us
<bot> Server on 3333 - Online
<bot> Server on 3334 - Online
<bot> Server on 80 - online
<user> !status ltc-eu
<bot> Server on 3333 - Online
<bot> Server on 3334 - Online
I know this is a bit different than the original code up top but can this be done? |
|
| Back to top |
|
 |
freelance Voice
Joined: 23 Dec 2013 Posts: 12
|
Posted: Tue Dec 24, 2013 1:50 pm Post subject: |
|
|
decided we need to change this a bit. No longer does it need user input. We need it to run in the background and monitor the ip addresses and ports to make sure they are still up. If once goes down it needs to alert the channel every 5 minutes until it goes back online.
Site 1 needs to be checked on ports 80,3333,and 3334
Site 2 needs to be checked on ports 3333, and 3334
Site 3 needs to be checked on ports 80 and 3335
Site 4 needs to be checked on port 3335
Site 5 needs to be checked on port 3336
If one of the sites goes down it needs to alert something like this. "Site 1 on port 3333 is having connection issues. Management is working on bring it back up as quickly as possible. Please try connecting to another site in the mean time. Thank you." Alert can just be a message put into the channel every 5 minutes until the site is back online.
Can someone help with this? I have no clue where to start with something like this. |
|
| Back to top |
|
 |
x0x Op
Joined: 10 Feb 2009 Posts: 140
|
Posted: Tue Dec 24, 2013 9:25 pm Post subject: |
|
|
| Interested in this as well! |
|
| Back to top |
|
 |
freelance Voice
Joined: 23 Dec 2013 Posts: 12
|
Posted: Mon Dec 30, 2013 2:41 am Post subject: |
|
|
Is anyone able to make this? Or could you get me started and point me in the right direction.
Maybe give me an example of how to scan an ip for a specific port. If it fails post to a channel. Scan every 5 minutes. If you can show me how to do that with 1 ip and port I should be able to finish it from there. |
|
| Back to top |
|
 |
heartbroken Op

Joined: 23 Jun 2011 Posts: 106 Location: somewhere out there
|
Posted: Mon Dec 30, 2013 10:34 am Post subject: |
|
|
you can use "nmap" : http://nmap.org/book/man.html
to scan an IP/port/s ..
(if doesn't exists on your system.you can ask your system admin or if you have root Access you can install your own for this job)
you can use bind time or bind cron to call the proc in every x minutes : http://www.eggheads.org/support/egghtml/1.6.21/tcl-commands.html#binda
and set cmd "nmap command.." and catch {eval exec $cmd} output; then foreach and split $output \n and do whatever you want with $output lines.. _________________ Life iS Just a dReaM oN tHE wAy to DeaTh |
|
| Back to top |
|
 |
freelance Voice
Joined: 23 Dec 2013 Posts: 12
|
Posted: Mon Dec 30, 2013 3:35 pm Post subject: |
|
|
I drew up a quick flow chart to show and example of what I am trying to do. It only shows 3 ip spots and ports but is expandable to many more.
 |
|
| Back to top |
|
 |
freelance Voice
Joined: 23 Dec 2013 Posts: 12
|
Posted: Tue Jan 07, 2014 4:19 am Post subject: |
|
|
Someone suggested using something like this. Or could use nmap to call websites from a txt file. Im just not sure how to write everything to have ti do what i need.
| Code: | | set ncmd "nmap -p80 google.com";catch {eval exec $ncmd} out;set i 0;foreach line [split $out "\n"] {;if while{ $i < 4} break;incr i;if {![string equal -nocase "up" [string range $line 8 9]]} {;puthelp "privmsg #chan :No response from web server on port 80";} else {;# do nothing;return 0;} } |
|
|
| Back to top |
|
 |
doggo Halfop
Joined: 05 Jan 2010 Posts: 97
|
Posted: Tue Jan 07, 2014 6:22 pm Post subject: |
|
|
| Code: | ############################################################
############################################################
# port_scan.tcl version 1
# by doggo 07/01/2014
# requires netcat to be installed on your server
# apt-get install netcat
# written for http://forum.egghelp.org/viewtopic.php?t=19579
# available to download from http://gotcode4u.com/
############################################################
############################################################
bind time -|- "?0 * * * *" port_scan
bind time -|- "?5 * * * *" port_scan
set report_chan "#yourchan"
proc port_scan {minutes hours days months years} {
global report_chan
array set server_infos {
0 "gotcode4u.com 80"
1 "google.co.uk 80"
2 "google.com 443"
3 "egghelp.org 80"
4 "yourserverip.org 80"
5 "yourotherserverip.org 80"
}
variable isbackcheck
foreach { server ip_info } [array get server_infos] {
set ip [lindex $ip_info 0]
set port [lindex $ip_info 1]
catch {eval exec nc -zvv $ip $port} scan
regsub -all -- {\n} $scan " " scan
if {[string match "*Connection refused*" $scan] || [string match "*forward host lookup failed: Unknown host*" $scan]} {
puthelp "privmsg $report_chan :\002\00304\[INFO\]\017 $ip:$port is having connection issues. Management is working to bring it back as quickly as possible. Please try connecting to another site in the mean time, thank you."
putlog "\($server\) - Netcat Report - \[\[ $ip:$port is down \]\]"
set isbackcheck($server$ip) 1
} else {
if {[info exists isbackcheck($server$ip)]} {
puthelp "privmsg $report_chan :\002\00303\[INFO\]\017 Connection issues on $ip:$port have been resolved and all operations should be back to normal now, thank you for your patience."
catch {unset isbackcheck($server$ip)}
}
putlog "\($server\) - Netcat Report - \[\[ $ip:$port is ok \]\]"
}
catch {unset scan}
}
}
putlog "port scan version 1 loaded!" |
tested a lil works fine as far as i can see enjoy _________________ NON geeky!! http://gotcode4u.com/
Last edited by doggo on Wed Jan 15, 2014 12:27 pm; edited 1 time in total |
|
| Back to top |
|
 |
freelance Voice
Joined: 23 Dec 2013 Posts: 12
|
Posted: Tue Jan 07, 2014 7:30 pm Post subject: |
|
|
| That seems to work but I intentionally put in a bad ip and port and it still returns it as good. |
|
| Back to top |
|
 |
doggo Halfop
Joined: 05 Jan 2010 Posts: 97
|
Posted: Wed Jan 08, 2014 5:53 am Post subject: |
|
|
what does it return from cmd line using nc -zvv badip badport?
outputs i get in log are:
| Code: |
[14:00] (0) - Netcat Report - [[ gotcode4u.com:80 is ok ]]
[14:00] (1) - Netcat Report - [[ google.co.uk:80 is ok ]]
[14:00] (2) - Netcat Report - [[ google.com:443 is ok ]]
[14:00] (3) - Netcat Report - [[ egghelp.org:80 is ok ]]
[14:00] (4) - Netcat Report - [[ yourserverip.org:80 is down ]]
[14:00] (5) - Netcat Report - [[ yourotherserverip.org:80 is down ]]
|
0-3 should be ok 4-5 do not exist so will trigger the alert
in the channel every 5 mins..
| Code: |
[10:00] <eggy> [INFO] yourserverip.org:80 is having connection issues. Management is working on bring it back up as quickly as possible. Please try connecting to another site in the mean time. Thank you.
[10:00] <eggy> [INFO] yourotherserverip.org:80 is having connection issues. Management is working on bring it back up as quickly as possible. Please try connecting to another site in the mean time. Thank you.
|
i did use example.org to start with, but that actually existed and never triggered the alert..
prolly just a diff error code that needs handling, i only ran into 2 when testing  _________________ NON geeky!! http://gotcode4u.com/ |
|
| Back to top |
|
 |
freelance Voice
Joined: 23 Dec 2013 Posts: 12
|
Posted: Wed Jan 08, 2014 10:50 am Post subject: |
|
|
I put in all my servers and they all come back ok. I then put back in the bad server and ip and this is how it returns.
[14:45:01] (6) - Netcat Report - [[ yourserverip.org:80 is ok ]]
I even tried changing it from Connection refused to timed out and still same result. So everything good or bad is returning as ok.
I run this separately to verify sites are down. I put in !sitetest yourserverip.org and it comes back and says the site is down.
| Code: | # Usage example: !sitetest egghelp.org
bind pub - !sitetest site:test
proc site:test {n u h c a} {
if {[catch {set site_test [socket -async $a 80]} sockerr]} {
putserv "privmsg $c :$a is Down"
} else {
putserv "privmsg $c :$a is Up"
}
if {[info exist site_test]} {close $site_test}
}
putlog "Site Test loaded.."
|
|
|
| Back to top |
|
 |
doggo Halfop
Joined: 05 Jan 2010 Posts: 97
|
Posted: Wed Jan 08, 2014 1:19 pm Post subject: |
|
|
did you install netcat?
and from the linux terminal type:
| Code: |
nc -zvv yourserverip.org 80
|
output is or should be
| Code: |
yourserverip.org: forward host lookup failed: Unknown host
|
and from my eggdrops log
| Code: |
[21:10] (4) - Netcat Report - [[ yourserverip.org:80 is down ]]
[21:10] (0) - Netcat Report - [[ gotcode4u.com:80 is ok ]]
[21:10] (5) - Netcat Report - [[ yourotherserverip.org:80 is down ]]
[21:10] (1) - Netcat Report - [[ google.co.uk:80 is ok ]]
[21:10] (2) - Netcat Report - [[ google.com:443 is ok ]]
[21:10] (3) - Netcat Report - [[ egghelp.org:80 is ok ]]
|
script works as expected for me... _________________ NON geeky!! http://gotcode4u.com/ |
|
| Back to top |
|
 |
freelance Voice
Joined: 23 Dec 2013 Posts: 12
|
Posted: Wed Jan 15, 2014 5:30 am Post subject: |
|
|
Sorry it took so long to get back to this post. I have been a bit under the weather. Thats what it was. Works perfectly now. Had to get ahold of shell provider to have them install it since I wasn't allowed. Works like a charm now.
I do have one more question. Is it possible to have it where if an ip reports as down, the bot will message the channel like normal saying it is down. But the first time after reporting it down say the ip then comes back up. Is it possible to have the bot report something like "server issues have been resolved and all operations should be back to normal now, Thank you for your patience"
So something like this
1:05<bot> reporting to chan server is down
1:10<bot> reporting to chan server is down
1:15<bot> reports problems fixed server is back up
-then everything back to normal silence until server goes down again- |
|
| Back to top |
|
 |
doggo Halfop
Joined: 05 Jan 2010 Posts: 97
|
Posted: Wed Jan 15, 2014 12:28 pm Post subject: |
|
|
edited first post with changes  _________________ NON geeky!! http://gotcode4u.com/ |
|
| Back to top |
|
 |
|