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.

website up or down status

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
f
freelance
Voice
Posts: 12
Joined: Mon Dec 23, 2013 10:45 am

website up or down status

Post by freelance »

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

# 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?
f
freelance
Voice
Posts: 12
Joined: Mon Dec 23, 2013 10:45 am

Post by freelance »

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.
x
x0x
Op
Posts: 140
Joined: Tue Feb 10, 2009 6:42 am

Post by x0x »

Interested in this as well!
f
freelance
Voice
Posts: 12
Joined: Mon Dec 23, 2013 10:45 am

Post by freelance »

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.
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

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 ... 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
f
freelance
Voice
Posts: 12
Joined: Mon Dec 23, 2013 10:45 am

Post by freelance »

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.

Image
f
freelance
Voice
Posts: 12
Joined: Mon Dec 23, 2013 10:45 am

Post by freelance »

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

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;} }
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

Code: Select all

 ############################################################
 ############################################################
 # 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 :-D enjoy
Last edited by doggo on Wed Jan 15, 2014 12:27 pm, edited 1 time in total.
f
freelance
Voice
Posts: 12
Joined: Mon Dec 23, 2013 10:45 am

Post by freelance »

That seems to work but I intentionally put in a bad ip and port and it still returns it as good.
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

what does it return from cmd line using nc -zvv badip badport?


outputs i get in log are:

Code: Select all

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

[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 ;-)
f
freelance
Voice
Posts: 12
Joined: Mon Dec 23, 2013 10:45 am

Post by freelance »

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

# 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.."
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

did you install netcat?

and from the linux terminal type:

Code: Select all

nc -zvv yourserverip.org 80
output is or should be

Code: Select all

yourserverip.org: forward host lookup failed: Unknown host

and from my eggdrops log

Code: Select all

[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...
f
freelance
Voice
Posts: 12
Joined: Mon Dec 23, 2013 10:45 am

Post by freelance »

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-
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

edited first post with changes ;-)
Post Reply