Tagged: projects
I know I haven't written about much of the code I've written over the last couple years or so... as I don't consider myself a "programmer". I'm a Systems Administrator by trade but with a flare for scripting where I will write scripts to make my job easier (even so I no longer have to do my "job"). I've been learning python over the last year or so, and I think I'm really finally starting to get it and really be able to apply what I've learned to new scripts. Anyway, as a means to help me remember this and that maybe it could be helpful to someone else down the road. I'm not sure if there is a better way to do this or if this is the proper way. But what I was looking for was a way to be able to pass a generic name and do a LIKE sql search for it. My example is actually coming from using bacula at work, and I'm trying to get some better reporting and store some statistics(I will eventually post what I come up with...) Anyway, heres a bit of sample code to illustrate what I came up with(I run a postgresql database, but I don't believe it would be any different for mysql other than the original module).
#!/usr/bin/env python
import sys, psycopg
DSN = "dbname='bacula' user='bacula'"
class pgDB:
def db_connect(self, DSN):
try:
conn = psycopg.connect(DSN)
except StandardError, err:
print "Error: Unable to connec tot the database, exiting...", err
return Exception
else:
return conn
def do_query(self, conn, query, args=[]):
cur = conn.cursor()
try:
cur.execute(query, args)
result = cur.fetchall()
return result
except StandardError, err:
print "Error Executing Query: ", error
def main(clientName):
DB = pgDB()
try:
myDBconn = DB.db_connect(DSN)
except:
sys.exit()
clientName = "%" + clientName + "%"
query = "SELECT * FROM client WHERE name LIKE %s"
result = DB.do_query(myDBconn, query, [clientName])
print result
if __name__ == "__main__":
main("hostname")
Assuming the spacing is all correct, that should work. The key being having to append the %'s to the word we are searching for before it is injected into the predefined query... kinda weird how it does that as i was trying to have the %'s in the query before the clientname was injected having the query look like "LIKE %%s%" which was causing problems... and I suppose I can understand why...
Anyway, as I said, I'm not a programmer by any means, this is just some notes for myself. Maybe they will help someone else too...
Is it me or aren't there any decent open source time tacking/billing/invoicing? I'm looking for something with a client side GUI, don't think I'd really care about what kind of database back-end it has.... I'd just like a desktop app that can track projects and time spent on it. With an option for reporting and invoicing. I've been using GnoTime and I find it lacking. Its interface is unintuitive, and reporting features are somewhat lacking for what I want to do. I've been trying to figure out how to customize some reports for it. What I want is to be able to select a main project, and show total of whats been billed, whats paid, whats waiting to be paid ect... But be able to make that go narrower, down to a specific task if needed and still show the same things. GnoTime can do this, except for the reporting doesn't seem to work right. And as I said, the reporting is lacking. If I could find an easy way to create the GUI, I'd start working on all the backend stuff to create such a thing, but I find the free GTK+ Design tools kind of odd... I'm not a GUI designer in any sense of the word, so it could most definitely be me. But I've had to design some fairly ugly VB apps in the past and those were easy enough to create.... Wondering why there isn't something comporable for GTK+? I don't really want to do it in QT mostly because I use Gnome as my desktop and I want it to follow whatever theme I happen to be running at the time. Anyway, I my just happen to write one(in python), one of these days if I can find a suitable GUI builder.
January 16, 2006 Posted by mitch |
projects |
I figured writing out my upcomming projects might help me accomplish them a little better.... so here goes:
Need to buy another PVR-150/PVR-500 card for my MythTV box, and a different case to make it quiet. It will then need to be configured with the TV-out on the Nvidia card so it can sit in the living room.
Asterisk! I need/want to learn more about VOIP and gain some experience with it... What better way to do this than with setting up a home PBX? Hopefully when we move the house will be wired with Cat 5e or... guess what my first project will be? :) (We'll see if I can convice Elissa about that...)
Need to become more accustomed with CVS/Subversion, however, this I think will evolve from work and from an ongoing task of getting better at scripting. If I start using CVS/Subversion in the mix, this should be a piece of cake... Key is to get an editor that does it automagically to some degree... need to look into what vim can do more... if it will fit the bill then I'm set. (I hear its adopted some of the stuff Emacs can do...)
Home Automation, this is another area I want to dig into a bit. As its wicked cool, for the most part tho, its really getting devices to do what you need, and then writing the glue to make it all cohesive. It will however require some funding to make happen, thus it will need Elissa's write off :) More geek things to make her understand.
Thoughts:
Being both a car nut and a geek makes some things rather difficult... as I'm always wanting something... for one of the two... gradually, I'm slowly giving up the thought of ever being able to tune up my civic, and looking just to buy a car I'm going to be "ok" with as it sits stock. These thoughts have forced me to *REALLY* want a Mitsubishi Evo. As I really don't know what else I'd want to do with it, other than maybe a new ECU chip, and maybe a different deck... but even then I think I'm leaning more towards going with a MP3 player with FM transmitter so a different deck wouldn't be nessisary. They're still somewhat expensive tho, so I might have to settle for a Civic Si if I end up selling/trade in my current civic. Or I might end up just hanging on to my Civic untill I can afford an Evo... (which ever comes first in the next two years) Anyway, we'll see.
I've decided to learn python. I've been writting a could hacks here and there to get a feel for the language so far so good. The language itself it fairly simple with alot of power packed into it. Reading other peoples code isn't bad either. (Which is the rep perl has...) I'll link up some of my code once its "ready". I just got "Python Cookbook" in the mail today. So I think I'll hit it for the next hour or so and see what happens.
I wrote a simple bash script to resize images I pull off my digital camera because resizing all of the AutoExpo images was a royal pain... Anyway, it does *very* little error checking (basically only checks to make sure you gave it atleast one argument...) so use it at your own risk!
#!/bin/bash
# bash script to automatically scale images to 25% of their original size
# using ImageMagik.
if [ ! -n "$1" ]
then
echo "Usage: `basename $0` [image path]/ [new resized path]/"
exit
fi
for file in `ls $1`; do
convert -monitor $1$file -resize 25% +profile "*" $2$file
done;
I've almost finished a script to dump the data from dhcp leases to mysql at work. I just have the database part to finish which I should be able to get to tomarrow hopefully. Anyway, I will post it when I finish it. I'm not promising anything pretty... infact its actually REALLY ugly. Anyway, I will post it none the less. Guess its time I get a projects page up eh?
I'm finally breaking down and going to really learn php classes. I've found that in order to duplicate how this site works for my own needs, I'm going to have to learn classes. That way I can seamlessly use smarty for templates, and somehow implement a plugin system so I can create a base Authentication, User Administration, Site Administration, and Themes, and then be able to plug in different "sites" into that framework without much trouble. I might eventually release the source for it, as I don't believe there are many frameworks that are simple. They all try to implement some type of api to plug into... Where I think mine (atleast will start out this way) won't have one really... just have to include a different class, and add it to the main navigation links... Anyway, those are some thoughts, i will keep this updated with my progress.
At work we use a program called "QuickDNS" for managing our domains for both testing, development and production environments. The problem is it is costly, and to do what we need it to, will cost even more. So, over the last couple of days, I've been contemplating how to write my own, something that just does DNS, because thats all we need. The basics would really be pretty simple, the only thing that makes me think it will be difficult is "checking" to make sure the user of the web app is aware of what they are doing. So they don't screw things up. But I guess that would be possible with the program we are using currently. It doesn't do that many checks, so it is possible to screw up a server if the user doesn't know what they are doing. I'm hoping that after I get all my servers upgraded to RHEL3, I will have a bit more time to play with such an idea, but really I think it would take me about a week to get something working and only minor bugs needing to be worked out. But maybe I'm just being over zealous about it. But then again, its just another project for me to work on. Along with the System Information database... As soon as I get a basic framework for either of them, they both will be able to be plugged into it however. Which will be nice.
Ok,
I don't get it... is dhcp the red headed step child of all IT services? I mean the lack of managment tools for it is rediculous. After reading tons of docs, and the DHCP Handbook(2nd edt.) and even more forum postings... it seems that its annoying enough that it would be nice to get it fixed... but no one seems to have any kind of solution. A little more about what I'm refering too... I would like a script that parses through the dhcpd.leases file and either out puts totals of various lease information based on criteria I specify. OR does a straight dump to a database, and then can be queried in anyway needed. I would think this isn't an uncommon request, just no one has done anything about it, because it will be a HUGE pain.
Honestly... I don't think it would be THAT hard to accomplish this. However, I understand that the dhcpd.leases file isn't kept in the best format for such a thing.
Anyway, this is what I'm thinking. Two scripts, First(1) would be an initialization script of such. Basically it would be to initialize the database and update IP's. Anytime the you added a pool or changed a range of IP's, this script would to be run. Its purpose would be to look at all the ranges in the dhcpd.conf file, and create the rows in a table for EACH ip in those ranges(creating a defacto list of ALL ips the DHCP server is going to be serving). Then the Second(2) script would be cron'd to run every 5 min or however often you wanted it to run. It would then parse through the dhcpd.leases file, and for every IP, it would update that lease information into that IP's row in the database(that is why the IP would be the defacto... as there should only be one listing of it). I am uncertain at this moment, if an IP will be listed more than once in the dhcpd.leases file. As I don't know if the DHCP server always creates a new entry everytime it does something with a particular lease, and how often it removes them if that is the case. (hope that makes sence... for me in the future...), anyway, if all it has to do is do a update on that IP's row in the DB, creating a web app to parse through that information is trivial.
Anyway... just another project I've come up with that would make my job easier...
K, at work it would be very usefull if I had a system information/management web app for all the servers I'm over at work. While I'm thinking about it, I need to write down some of the things it should do. (I'm writing my own because I don't like the current ones out there)
- Store System Info (Name, DNS host names, IP, Subnet, Rack, Maker/model, serial num, service num, Purpose, apps installed, maintenance info, and anything else that might come up)
Should have a page that allows for a scripted update of the hosts file (ie: out put localhost, and all the other systems(or group of systems) in the DB with the IP boxname dns host name.)
What would be nice, is enough information, that the box could be duplicated without even needing access to it. (creating a kickstart based off installed apps and such)
Thats all I'm thinking about right now... and I hope thats enough detail that when I revisit this idea(when I actually have time to revist, in the process of redoing DHCP, DNS and Upgrading systems to RHEL3 right now...) that I can remember all that I'm thinking about right now.