[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Error messages and CGI

Henrik Ronellenfitsch

2/8/2005 3:58:00 PM

Hello,
is it possible to let ruby print error messages directly as text to the
cgi-output, like the way php prints it's error messages?
It's kind of impractical to always have to check the apache error log.

Thanks,
Henrik
7 Answers

Matt Armstrong

2/8/2005 11:45:00 PM

0

Henrik Ronellenfitsch <hen_WEG_damit_rik@searinox.de> writes:

> Hello,
> is it possible to let ruby print error messages directly as text to the
> cgi-output, like the way php prints it's error messages?
> It's kind of impractical to always have to check the apache error log.
>
> Thanks,
> Henrik

This approach will cause any exception in my main() function to be
printed out for the user to see. Syntax errors won't be caught, of
course, but even that can be handled by making the main .cgi script a
tiny wrapper with all the logic in a separate file that is loaded
within the begin...rescue...end. I stick my whole script in a timeout
block, since I've had odd problems cause a script to hang forever,
causing bad load on the HTTP server.

def exception_string(cgi, exception)
s1 = cgi.h1{"Exception:"} +
CGI::escapeHTML(exception.inspect) +
cgi.h1{"Backtrace:"}
s2 = ""
exception.backtrace.each { |line|
s2 = s2 + CGI::escapeHTML(line) + cgi.br
}
return s1 + s2
end

cgi = CGI::new('html4Tr')
begin
timeout(60 * 10) {
main(cgi)
}
rescue Exception => exception
cgi.out {
cgi.html {
cgi.head {
cgi.title { "#{TITLE}: Exception" }
} +
cgi.body {
exception_string(cgi, exception)
}
}
}
end

--
matt


Patrick May

2/10/2005 6:46:00 AM

0

Henrik,

On Tuesday, February 8, 2005, at 11:00 AM, Henrik Ronellenfitsch wrote:

> is it possible to let ruby print error messages directly as text to
> the cgi-output, like the way php prints it's error messages?
> It's kind of impractical to always have to check the apache error log.

To do this properly, you need to make the ruby interpreter web-aware.
This way you can catch SyntaxErrors. The development version of Narf
has such an interpreter. What platform are you working on?

In a month or so, Narf will have a major release. If you can't wait
and use subversion, you can check out narf at:

http://svn.narf-lib.org/svn/n...

Cheers,

Patrick



Henrik Ronellenfitsch

2/10/2005 4:44:00 PM

0

Thank you both very much

FNL

7/18/2010 8:19:00 PM

0



"i dude eclair" <br26354@yahoo.co.uk> wrote in message
news:Xns9DB99C57955Cbr26354yahoocouk@74.209.136.83...
> "Pegasus [MVP]" <news@microsoft.com> wrote in
> news:ep2CF6pJLHA.5464@TK2MSFTNGP02.phx.gbl:
>
>>
>>
>> "i dude eclair" <br26354@yahoo.co.uk> wrote in message
>> news:Xns9DB9789105DAFbr26354yahoocouk@74.209.136.86...
>>> Hi
>>>
>>> our W2K3 servers are too small to justify 3rd party applications or
>>> hardware.
>>>
>>> Is there a way to send notifications to the LAN clients when the
>>> servers lose AC power?
>>>
>>> Ideally - inform them when AC is restored as well.
>>>
>>> thanx
>>>
>>
>> Every UPS I have purchased so far came with a CD with management
>> software that did all of the above. What does yours do? If it only
>> writes an event to the Event Logger then you could pick up these
>> events with a VB Script and generate some EMail message.
>>
>>
>
> the application delivered is only for local use
>
> Event ID is ambiguous (7035) - nothing specific to the UPS device

- Does the text for event 7035 tell you what happened?
- Is the the same ID and text for mains failure & mains restoration?

Since the mains supply to your server is not affected by a mains failure,
only the UPS will know what's happened. Your only chance at creating a
notification is to find an unambiguous signal from the UPS.

If this is not possible then a crude alternative would be to connect some
old IP-device to the network (e.g. a router or printer server). If it
derives its power supply from the same outlet as the UPS then the lack of a
ping response would signal a mains failure.

i dude eclair

7/18/2010 11:58:00 PM

0

"Pegasus [MVP]" <news@microsoft.com> wrote in
news:ueZKGarJLHA.2276@TK2MSFTNGP06.phx.gbl:

>
>
> "i dude eclair" <br26354@yahoo.co.uk> wrote in message
> news:Xns9DB99C57955Cbr26354yahoocouk@74.209.136.83...
>> "Pegasus [MVP]" <news@microsoft.com> wrote in
>> news:ep2CF6pJLHA.5464@TK2MSFTNGP02.phx.gbl:
>>
>>>
>>>
>>> "i dude eclair" <br26354@yahoo.co.uk> wrote in message
>>> news:Xns9DB9789105DAFbr26354yahoocouk@74.209.136.86...
>>>> Hi
>>>>
>>>> our W2K3 servers are too small to justify 3rd party applications or
>>>> hardware.
>>>>
>>>> Is there a way to send notifications to the LAN clients when the
>>>> servers lose AC power?
>>>>
>>>> Ideally - inform them when AC is restored as well.
>>>>
>>>> thanx
>>>>
>>>
>>> Every UPS I have purchased so far came with a CD with management
>>> software that did all of the above. What does yours do? If it only
>>> writes an event to the Event Logger then you could pick up these
>>> events with a VB Script and generate some EMail message.
>>>
>>>
>>
>> the application delivered is only for local use
>>
>> Event ID is ambiguous (7035) - nothing specific to the UPS device
>
> - Does the text for event 7035 tell you what happened?
> - Is the the same ID and text for mains failure & mains restoration?
>
> Since the mains supply to your server is not affected by a mains
> failure, only the UPS will know what's happened. Your only chance at
> creating a notification is to find an unambiguous signal from the UPS.
>
> If this is not possible then a crude alternative would be to connect
> some old IP-device to the network (e.g. a router or printer server).
> If it derives its power supply from the same outlet as the UPS then
> the lack of a ping response would signal a mains failure.
>
>

7035 is a generic start/stop indicator - nothing specific for the device


but the description reads "The APC UPS Service service was successfully
sent a start control."




FNL

7/19/2010 5:19:00 AM

0



"i dude eclair" <br26354@yahoo.co.uk> wrote in message
news:Xns9DB9CB0C0101Bbr26354yahoocouk@74.209.136.86...
> "Pegasus [MVP]" <news@microsoft.com> wrote in
> news:ueZKGarJLHA.2276@TK2MSFTNGP06.phx.gbl:
>
>>
>>
>> "i dude eclair" <br26354@yahoo.co.uk> wrote in message
>> news:Xns9DB99C57955Cbr26354yahoocouk@74.209.136.83...
>>> "Pegasus [MVP]" <news@microsoft.com> wrote in
>>> news:ep2CF6pJLHA.5464@TK2MSFTNGP02.phx.gbl:
>>>
>>>>
>>>>
>>>> "i dude eclair" <br26354@yahoo.co.uk> wrote in message
>>>> news:Xns9DB9789105DAFbr26354yahoocouk@74.209.136.86...
>>>>> Hi
>>>>>
>>>>> our W2K3 servers are too small to justify 3rd party applications or
>>>>> hardware.
>>>>>
>>>>> Is there a way to send notifications to the LAN clients when the
>>>>> servers lose AC power?
>>>>>
>>>>> Ideally - inform them when AC is restored as well.
>>>>>
>>>>> thanx
>>>>>
>>>>
>>>> Every UPS I have purchased so far came with a CD with management
>>>> software that did all of the above. What does yours do? If it only
>>>> writes an event to the Event Logger then you could pick up these
>>>> events with a VB Script and generate some EMail message.
>>>>
>>>>
>>>
>>> the application delivered is only for local use
>>>
>>> Event ID is ambiguous (7035) - nothing specific to the UPS device
>>
>> - Does the text for event 7035 tell you what happened?
>> - Is the the same ID and text for mains failure & mains restoration?
>>
>> Since the mains supply to your server is not affected by a mains
>> failure, only the UPS will know what's happened. Your only chance at
>> creating a notification is to find an unambiguous signal from the UPS.
>>
>> If this is not possible then a crude alternative would be to connect
>> some old IP-device to the network (e.g. a router or printer server).
>> If it derives its power supply from the same outlet as the UPS then
>> the lack of a ping response would signal a mains failure.
>>
>>
>
> 7035 is a generic start/stop indicator - nothing specific for the device
>
>
> but the description reads "The APC UPS Service service was successfully
> sent a start control."

Well, this doesn't seem too hard. Try the script below. It is based on an
idea by the Scripting Guy.

iEventID = "'7035'" 'Watch out for the single/double quotes!

Set objWMIService = GetObject("winmgmts:{(Security)}\\.\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("Select * from __InstanceCreationEvent Where " _
& "TargetInstance ISA 'Win32_NTLogEvent' " _
& "and TargetInstance.EventCode = " & iEventID)

Do
Set objLatestEvent = colMonitoredEvents.NextEvent
If InStr(1, objLatestEvent.TargetInstance.Message, "APC UPS", 1) > 0 _
Then SendMessage objLatestEvent.TargetInstance.Message
Loop

Sub SendMessage (sText)
WScript.Echo sText
schema = "http://schemas.microsoft.com/cdo/configurat...
Set objEmail = CreateObject("CDO.Message")
cdoBasic=1
With objEmail
.From = "Joe@company.com"
.To = "Jack@company.com"
.Subject = "RAID disk failed"
.Textbody = Now & ": " & sText
With .Configuration.Fields
.Item (schema & "sendusing") = 2
.Item (schema & "smtpserver") = "mail@company.com"
.Item (schema & "smtpserverport") = 25
.Item (schema & "smtpauthenticate") = cdoBasic
End With
.Configuration.Fields.Update
.Send
End With
End Sub

Al Dunbar

7/20/2010 4:14:00 AM

0



"i dude eclair" <br26354@yahoo.co.uk> wrote in message
news:Xns9DB9CB0C0101Bbr26354yahoocouk@74.209.136.86...
> "Pegasus [MVP]" <news@microsoft.com> wrote in
> news:ueZKGarJLHA.2276@TK2MSFTNGP06.phx.gbl:
>
>>
>>
>> "i dude eclair" <br26354@yahoo.co.uk> wrote in message
>> news:Xns9DB99C57955Cbr26354yahoocouk@74.209.136.83...
>>> "Pegasus [MVP]" <news@microsoft.com> wrote in
>>> news:ep2CF6pJLHA.5464@TK2MSFTNGP02.phx.gbl:
>>>
>>>>
>>>>
>>>> "i dude eclair" <br26354@yahoo.co.uk> wrote in message
>>>> news:Xns9DB9789105DAFbr26354yahoocouk@74.209.136.86...
>>>>> Hi
>>>>>
>>>>> our W2K3 servers are too small to justify 3rd party applications or
>>>>> hardware.
>>>>>
>>>>> Is there a way to send notifications to the LAN clients when the
>>>>> servers lose AC power?
>>>>>
>>>>> Ideally - inform them when AC is restored as well.
>>>>>
>>>>> thanx
>>>>>
>>>>
>>>> Every UPS I have purchased so far came with a CD with management
>>>> software that did all of the above. What does yours do? If it only
>>>> writes an event to the Event Logger then you could pick up these
>>>> events with a VB Script and generate some EMail message.
>>>>
>>>>
>>>
>>> the application delivered is only for local use
>>>
>>> Event ID is ambiguous (7035) - nothing specific to the UPS device
>>
>> - Does the text for event 7035 tell you what happened?
>> - Is the the same ID and text for mains failure & mains restoration?
>>
>> Since the mains supply to your server is not affected by a mains
>> failure, only the UPS will know what's happened. Your only chance at
>> creating a notification is to find an unambiguous signal from the UPS.
>>
>> If this is not possible then a crude alternative would be to connect
>> some old IP-device to the network (e.g. a router or printer server).
>> If it derives its power supply from the same outlet as the UPS then
>> the lack of a ping response would signal a mains failure.
>>
>>
>
> 7035 is a generic start/stop indicator - nothing specific for the device
>
>
> but the description reads "The APC UPS Service service was successfully
> sent a start control."

Does the documentation indicate that this indicates some aspect of the
status of the power supply? IMHO, most of the "successfully sent a start
control" events indicate that a service is started on bootup of the server.
If the service designed to detect power issues were to stop itself when the
UPS was running on battery, it would no longer be available to detect the
restoration of mains power.

There might be some documentation with your UPS service that explains how
you can have it log the powerfail and powerrestore events you are interested
in. Or perhaps you can have it send a message to a distribution list.

/Al