CONTENTS OF THIS SITE

OUR OTHER CONTENTS

RECENT BLOG ENTRIES

A quick (and dirty?) way to mail Oracle alerts.

June 6th, 2008 by comment gennipher

Where I work, we have about 45 external Oracle Database Servers running RHEL 3. It’s a little tough keeping up with all of them day to day, so I made a quick BASH script that will check for any ORA- alerts in your Oracle alert_*.ora file. Here goes:
********************************
#!/bin/sh

tail -500 /usr/oracle/admin/ora_sid/bdump/alert_sid.log | grep ORA- > mailoraalerts.log
wc -l mailoraalerts.log > greporacount.txt
COUNT=`awk ‘{print $1}’ greporacount.txt`
if [ $COUNT -gt 0 ]; then
mail -s “Check ” your.address@mail.net < mailoraalerts.log
fi
********************************

So what this does is greps the last 500 lines of your alert log looking for ORA- string, and pipes that out to a log file. It then does a word count on that log file. If the word count is greater than 0 (there exists ORA- errors) then email me what the error is.

Then just schedule a cron job to run at whatever interval you desire. This probably isn’t the prettiest way to do this, I’d love to see other suggestions if anyone has any! My next step is to find out how to get Oracle to email me directly when there’s an error, instead of having cron determine when I am alerted.

Enjoy!

ˆ Back to top

Multiple object forms, delegation, and has_one…

June 3rd, 2008 by comment desi

I had an ah ha moment that maybe shouldn’t have been such an ah ha moment but it was so I figured I would share it. Yeah so I am sure most of us have had a situation where we needed to have multiple model forms. Most of the time now days I use attribute_fu to solve this issue but attribute_fu doesn’t work with has_one associations. Today I had a situation where I had two fields that were required for a has_one association object. Long story short it came to me that if we just used the delegate method provided by rails that we could essentially act like the attributes we were setting were on the parent model. This meant we only needed to create one form with multiple fields even though some of those fields were actually on a different model. I then remembered that back when I was working with the guys over at ThoughtWorks that we used a Ruby Extension called Forwardable to be able to delegate multiple attributes on one object.

So instead of this:

delegate :first_name, :to => :profile
delegate :last_name, :to => :profile
delegate :some_other_attribute, :to => :profile

side note: I’m not sure but I don’t believe delegate can take multiple attributes (I tried to look this up but for some reason couldn’t find the documentation for this method and didn’t have time to dig in the code)

You could do the following:

include the Ruby Extension Forwardable in the parent model class


include Forwardable

and then add this line:

def_delegators :profile, :first_name, :last_name, :some_other_attribute

So yeah that was my little ah ha moment. I am sure there are even better ways than this but this was better than what we were looking at doing to begin with.

ˆ Back to top