GZip IIS logs in four lines of ruby
Posted by Sam
I've been running IIS web servers for about 8 years now. I have to say that I'm not a big fan. It's more of a hassle to move and automate, especially compared to Apache. One of the things I haven't taken time to really take care of until now is managing the logs in an automated fashion. I decided it was time to take 5 minutes to handle this repetitive task. So I took a couple of minutes and installed Ruby 1.8.6 on the web servers and wrote the four line script to find and gzip all IIS log files excluding todays. Hopefully you find it useful.
ignore_file = Time.now.strftime 'ex%y%m%d.log'
Dir.glob 'C:/logs/**/*.log' do |f|
`c:/scripts/gzip.exe -9 #{f}` unless f.include? ignore_file
end
Nagios plugin for Apache
Posted by Sam
I've been using Nagios for years and for monitoring it's been great. The biggest problem is that there has never been a decent graphing solution that wasn't a giant pain in the butt. Thankfully that's no longer the case. I recently stumbled across pnp and it's been perfect. Good enough in fact that I've stopped looking for a replacement.
Since Phusion will now compile on Solaris I've switched from LiteSpeed back to Apache. Since going back to Apache I decided to dust off an old Nagios script I had for monitoring Apache's processes. It's pretty basic but it works with pnp to graph how busy your Apache servers are. Here's the script.
#!/opt/csw/bin/python
import httplib,re,sys,getopt
#Return codes
OK = 0
Warning = 1
Critical = 2
Unknown = 3
#Variables
hostname = ''
warningThreshold = -1
criticalThreshold = -1
def getUsers(hostname):
con = httplib.HTTPConnection(hostname)
con.request("GET", "/server-status")
res = con.getresponse()
results = res.read()
con.close()
match = re.search("\d+ requests currently", results)
if match:
newmatch = re.search("\d+", match.group())
if newmatch:
return int(newmatch.group())
else:
return -1
else:
return -1
def showUsage():
print sys.argv[0]+' -h -H hostname -w warning -c critical'
sys.exit()
#Get command line options
try:
optlist, args = getopt.getopt(sys.argv[1:], '-h-H:-w:-c:')
except:
showUsage()
for o, a in optlist:
if o == '-h':
showUsage()
sys.exit()
if o == '-H':
hostname = a
if o == '-c':
criticalThreshold = int(a)
if o == '-w':
warningThreshold = int(a)
# Validate command line options
if criticalThreshold == -1:
print 'critical threshold was not set'
showUsage()
if warningThreshold == -1:
print warningThreshold
print 'warning threshold was not set'
showUsage()
if hostname == '':
print 'hostname was not set'
showUsage()
try:
currentUsers = getUsers(hostname)
except:
print 'Unknown'
sys.exit(Unknown)
if currentUsers >= criticalThreshold:
print 'Critical: '+str(currentUsers)+' users|current_users='+str(currentUsers)
sys.exit(Critical)
elif currentUsers >= warningThreshold:
print 'Warning: '+str(currentUsers)+' users|current_users='+str(currentUsers)
sys.exit(Warning)
elif currentUsers >= 0:
print 'OK: '+str(currentUsers)+' users|current_users='+str(currentUsers)
sys.exit(OK)
else:
print 'Unknown'
sys.exit(Unknown)
Installing Phusion Passenger on Solaris
Posted by Sam
I know there are other places on the web where you can piece this together but I thought I'd throw up how I got Phusion Passenger compiled on a Solaris 10 zone with Blastwave packages. Well technically the packages are from opencsw.com but they should behave exactly the same (for now). Also, as of the time of this writing the most recent version (2.0.6) didn't compile. I had to grab the trunk from GitHub.
bash-3.00# crle -l /lib:/usr/lib:/opt/csw/lib
bash-3.00# export PATH=/opt/csw/apache2/bin:/opt/csw/apache2/sbin:$PATH
bash-3.00# export APXS2=/opt/csw/apache2/sbin/apxs
bash-3.00# export APR_CONFIG=/opt/csw/apache2/bin/apr-1-config
bash-3.00# gem install passenger
bash-3.00# ./bin/passenger-install-apache2-module
The first line is not something I use regularly and you definitely want to use it with care. Basically it tells the system where to find libraries. Before I added this line Ruby Enterprise Edition and Phusion couldn't find their runtime libraries unless I set LD_LIBRARY_PATH. Relying on LD_LIBRARY_PATH isn't a good idea and didn't work for daemons so I used crle instead. You should run crle first to make sure you don't have other paths set before overriding it.
Once everything finishes you should have a working Passenger install. Note this has only been tested on Solaris 10 x86 update 6. Also, one machine had the gnu version of ld installed and it was causing a weird error. Once I removed SUNWtoo it compiled fine.
JavaFX 1.0 is a big disappointment
Posted by Sam
Sun Microsystems has been doing so much right lately that I had really high hopes for JavaFX. Maybe too high. JavaFX 1.0 was released this week and I'm not ashamed to say that I'd been looking forward to it for a really long time now. A couple of really great features for GUI development were included and I THOUGHT they were making the code simpler.
First off I'd like to mention a couple of features that I think are fantastic for GUI development. Mainly binding and triggers. They do just what they sound like. For example you could have a central set of variables, say for example a bunch of preferences. Then wherever you want to use those preferences you just bind to the variable. Presto - bango. Anytime that variable changes everybody that is bound to that variable changes. Saves a TON of coding. The second feature is triggers. That is when a variable changes you can act on the knowledge that it changed. It's like creating Listeners without all the coding. And lastly being able to create applets that live beyond the browser is pretty cool. A completely separate threading model and everything. Cool indeed.
So where was I disappointed? Primarily I feel like they took a HUGE step backwards with their JSON support. Originally the examples showed that you could just make a one line JSON request and turn it into a real object. Nice huh? Simple and concise. Just how that task SHOULD be. Have a look at the ridiculous examples of using JSON in the 1.0 release. They have like 30 lines of code that say if ("string" == "value") then variable.something = json.something. It's just ridiculous. This is a very Java way to do it and something that's driven me nuts for years. There are Ruby libraries that can create first class objects from JSON and XML. Flex can do it. Why can't JavaFX. It shouldn't require so much code to do something so simple. Especially when it was doing it that way to begin with.
I've been playing with Adobe AIR lately and it's highlighted a couple of other problems that exist with JavaFX and really Java in general. I know they can be worked around with Java but I don't know how they can be worked around in JavaFX. With AIR I get a real icon for my program. It also shows up in the task list with the name that I give it. This isn't the case with Java. If you've got multiple processes running it can be hard to know which one is which. It also reinforces the Java brand more than my brand. AIR in general just has much better integration with the host OS. There are work arounds for traditional Java programs but this really needs to be something that Sun builds into Java and especially JavaFX.
I had a program that I was looking forward to using JSON, bindings and triggers on but frankly after working with Ruby on Rails for so long I have zero tolerance for excessive, silly code. I really, really wanted to use JavaFX for this app but it looks like it's going to be done in Adobe AIR. **SIGH**
Snort Alert Monitor 0.4.0 Released
Posted by Sam
SAM 0.4.0 has been released. Here's a highlight of features available in this release:
- Fixed a copy and paste bug where the dashboard only showed stats for the last 5 minutes instead of the last hour as was intended.
- Dashboard now updates automatically.
- And more...
Originally I had a few additional features scheduled for this release. However having the Dashboard refresh automatically seemed like something that would be useful for most people ASAP and was the driving factor that the original version of SAM was created for. So since I had this in place I decided to move the much less critical features to another release and get this one out the door.
Speaking of features - I've been able to crank through things much faster than on the previous version. This is largely in thanks to a LOT of great JQuery plugins and the fact that I switched from Java/Swing development to Ruby on Rails. If you've got ideas for things you'd like to see please let me know. Most of what's going in SAM right now is stuff that interests me. I can't promise I'll implement everything and a lot of stuff probably is better completed as plugins but if it makes sense I'll put it on the roadmap. And if it doesn't make sense but sounds like fun to me I might create a stand alone app that utilizes the API. So, give me your ideas!
Tags: sam