Archive by Author

Running and debugging a SQL Server 2000 DTS Package in Visual Basic 6.0

If you have a fairly complex DTS-package (Data Transformation Services) in SQL-Server 2000 and don’t have a clue of what it does and have a limited understanding of dts read this. You can ”export” the package to VB6 and by doing so you can read the code and run and debug the script from the VB6-IDE. You can even run it in VB.NET. This is quite old school but sometimes necessary to do in legacy systems if you want to edit a complex dts-script.

Step 1 – Export the dts-package to visual basic

Open your DTS-package in SQL-server 2000.

Choose ”Package -> Save as” in the menu and then change ”Location” to ”Visual Basic file” in the dialog. Press OK and then a bas-file (VB-module) is saved to disk.

Step 2 – Create a visual basic project

Open Microsoft Visual Basic IDE. Choose to create a new ”Standard EXE” project then click ”Open”. Remove the default Forms1 from the project. Then you add the dts bas-file to the project with ”Project -> Add module”. The result should should look like below.

Step 2 – Executing and debugging the dts-package

Go to ”Project -> References” and add references to ”Microsoft DTSPackage Object Library” and ”Microsoft DTS Custom Task Object Library”. Now you are ready to edit your package.

To debug the package you simply set a breakpoint and hit F5.

Now feel free to fool around with the package/module and make the changes that you need. It is not easy at first but after a while you get the hang of it.

Step 3 -Saving the dts-package to SQL-server

When your package is ready for deployment you can deploy it through VB. Instead of executing the package you can easily save it to your SQL-server.

Search for the ”Save or execute package” section in the module. Comment the Execute statement and uncomment the SaveToSQLServer row.

Hit F5 to run the module. If everything works fine your new dts-package shows up in SQL-server.

More help with DTS can be found and at sqldts.com/

MRTG and Cisco-problem for unrouted VLAN’s

We had a problem with mrtg (version 2.14.5) and Cisco-routers (Cisco IOS Software, c7600s72033). The problem was that cfgmaker did not find the 64-bit traffic counters for ”unrouted vlan’s”, instead it used the 32-bit counter. When the utilization of such a port reached above 100 Mbit the counter ”rolled over” to zero and the graph looked like it was cut.

If you need to troubleshoot cfgmaker you should use snmpwalk to manually look at the counters from the device that you are monitoring. By doing so you can watch the traffic-numbers from the source. These are some of the ones that cfgmaker uses.

Get basic system information
snmpwalk -c community -v 2c ip-address system

Listing 32-bit traffic counters
snmpwalk -c community -v 2c ip-address ifinOctets

Listing 64-bit traffic counters
snmpwalk -c community -v 2c ip-adress ifHCInOctets

Check the interfaces speed
snmpwalk -c community -v 2c ip-adress ifSpeed
snmpwalk -c community -v 2c ip-adress ifHighSpeed

Check status of the interfaces
snmpwalk -c community -v 2c ip-adress ifOperStatus
snmpwalk -c community -v 2c ip-adress ifAdminStatus

List everything about the interfaces
snmpwalk -c community -v 2c ip-adress if

When I tested my router I could clearly see that it had 64-bit counters. However, cfgmaker couldn’t find them. Why?

IF-MIB::ifHCInOctets.1 = Counter64: 0
IF-MIB::ifHCInOctets.11 = Counter64: 1436496000
IF-MIB::ifHCInOctets.21 = Counter64: 1657770660
IF-MIB::ifHCInOctets.31 = Counter64: 8220
IF-MIB::ifHCInOctets.41 = Counter64: 219538030

There is a bug that is responsible for this behavior. Maybe the bug belongs to Cisco because they mark these interfaces as having zero speed. Very strange!

The workaround is (as stated in the bug report) to modify row 907 in cfgmaker to:
if((!defined $speed) or $counter eq ”” or $counter !~ /\d/ or $SNMP_Session::errmsg or $Net_SNMP_util::ErrorMessage?){

If you want to debug cfgmaker change to the rows below in the beginning of the cfgmaker program-file:

@main::DEBUG=qw(base snpo coca);
#@main::DEBUG=qw();

Do something every X iteration in a bash loop

If you have a bash loop and want to ”do something” at every X iteration you are in trouble because bash isn’t that good with numbers. Anyway, today I created this small example that you can use. In my case I needed to read a pretty large txt-file and create a simple html output table of the rows. The problem was to insert TR-tags between the TD-tags like below:

td row 1
td row 2
td row 3
tr
td row 4
td row 5
td row 6
tr

My solution solved the problem! It is pretty helpful that we have the modulo (%) operator in bash.

#!/bin/bash

# Change this to how many rows row you want to skip before doing something
doevery=3

for (( c=1; c<=100; c++ ))
do
	remainder=`expr $c % $doevery`
	echo "Remainder: $remainder"

	if [ $remainder = "0" ];	then
		echo "Every $doevery iteration"
		# Do something
	fi

done

Mina försök att använda HTPC’n som trådlös router i Windows 7

Jag har under sommaren laborerat med min HTPC så att den ska kunna dela ut mobilt bredband i sommarstugan med Windows 7 utan att behöva koppla in någon router. Man kan ju förvandla sin Windows 7 dator till att fungera som en trådlös router genom att använda ConnectifyMe, Virtual Router eller att använda sig av kommandoraden.

Jag har nu efter 1 månads testning gett upp försöket efter att ha testat alla dessa lösningar. Det som jag fick att fungera bäst var kommandorads-versionen men även den fungerade dåligt i längden. Det första jag märkte var att det sög rätt mycket kräm ur HTPC’n som skulle fungera som WIFI-hotspot (även om inga klienter var inkopplade). Det andra var att internet-uppkopplingen till de trådlösa klienterna försvann med jämna mellanrum. Jag testade med två olika 3G-modem i HTPC’n och uppkopplingen dog ändå. Vet inte vad det berodde på och orkar inte undersöka det mer, men antagligen är det något internt i Windows som spökar. Det lustiga var att uppkopplingen i vissa fall fungerade i själva HTPC’n men inte i trådlösa nätet. Det tredje ”dåliga” var att man inte har sån stor koll på vad som händer i nätet och man har inga möjligheter att ställa in de parametrar som vanligtvis finns i en router. Och till sist så tyckte jag att throughput’en (hastigheten) på trådlösa nätet försämrades drastiskt.

Nu har jag alltså gett upp och delar ut mobilt bredband trådlöst med en vanlig hårdvaru-router inkopplad till HTPC’n istället. Hur man gör detta kan man läsa här. Detta fungerar nu mycket bättre. Om M$ hade lagt lite mer tanke bakom den här funktionaliteten så hade det varit en riktig ”killer-feature”, men nu känns det lite väl omoget.

My list of useful firefox plugins

As a web-developer your most valuable tool is Firefox. Here is a list of the plugins I couldn’t live without:

Firebug – Web developer tool
IE Tab 2 – For browsing crappy webpages (and Logica internal web)
Xmarks BYOS edition – Syncing bookmarks between computers using my own server
Svensk ordlista – Swedish spelling dictionary
YSlow – Firebug web performance tool
PDF Download – Regain control of pdf files opening in your browser window
Download statusbar – Manage downloads from the statusbar
Foxyproxy standard – Good tool when working at different companies with different proxies

Rengöra förgasare med ultraljudstvätt

Nu är det båtsäsong och självklart ska båtmotorn jävlas. Motorn är en Yamaha 20-hästars utombordare från 80-talet. Den har aldrig gått riktigt bra varken för oss eller den tidigare ägare. Motorn har tidigare gått någorlunda bra men till denna säsong så totalvägrar den. Vad gör man? Efter att ha testat ”allt” så kom jag till slut på lösningen…

Symptom
Motorn går bra på tomgång men så fort man gasar så går den bra i en sekund och sedan dör den. Om man manuellt ändrar tomgången kontinuerligt medan man kör så går det att komma upp i planing. Justering av luft/bränsle-skruven ger ingen skillnad överhuvudtaget i ”gången”.

Lösning
Efter att ha öppnat förgasaren så såg jag att det såg väldigt skitigt ut trots att jag försökte mig på en rengöring senast ifjol. Jag kom då på att jag kunde rengöra den med ultraljudstvätten som jag köpte för att rengöra flipperspelsdelar. Denna köpte jag ifjol på Kjell&Co, artnr 40490.

Förgasaren är lite större än min ultraljudstvätt så jag fick köra förgasaren i omgångar. I vattenbadet så hade jag varmt vatten och vanligt diskmedel. Efter att ha plockat isär förgasaren och sedan kört den i tvätten i några minuter så tog jag ut den och såg att den verkligen hade blivit totalren, som ny! Jag blir lika förvånad över vilket bra resultat jag får av denna maskin varje gång jag använder den.

Efter att ha satt tillbaka förgasaren på motorn och ställt in luft/bränsle blandningen så gjorde jag en provkörning tills havs. Det visade sig att motorn nu gick helt perfekt. Bättre än den någonsin gått tidigare. Så att rengöra förgasare med ultraljudstvätt är något som jag verkligen rekommendera. Det tar bara några minuter och du slipper hålla på med olika vätskor och blåsa rent och jävlas.

My Windows 7 experiences and setup

One year has passed since my first tryout of Windows 7. The transition from Windows XP was easy and I won’t go back. Well thats not entirely correct, because my arcade machine (coming up blogpost) run a very fast and good version of XP called Tiny XP.

I have had the same ”install” the entire year and tried a lot of things with it. The usual problem with having the same install too long has now began to show itself. More problem than I can handle! The only solution is as usual to reinstall everything. This time I am going with a dual-boot setup with Win7 and Ubuntu.

The most annoying thing with ”Windows 7″ has so far been the new ”Windows explorer” (explorer.exe) which I think is bloated. There is no way that I can be productive as earlier with that crap. And I can’t even make it work in ”classical mode”. I have stopped using it! The most perfect file browser in my mind is the classical windows explorer which Microsoft stopped using with Windows XP. I have tried a lot of file browsers and xplorer² is a good replacement. That program is actually the first program I install on a new computer.

Some of my setup tweaks

Lets share some of the tweaks I use to make my Win7 feel good. It is also good for me to have a checklist when I install Win7 the next time.

1) Live Messenger

Minimize Windows Live Messenger to systray

Make Live Messenger cleaner by patching it

2) Taskbar and systray

Bring back good old ”Quick launch”

Unpin all programs from taskbar

Taskbar properties: Check ”Use small icons” and ”combine when taskbar is full”

3) Personalize

In the beginning I switched of all aero stuff and used ”Windows Classic” theme. But by now I am actually used to all fancy aero stuff and it doesn’t feel that my machines performance is that much affected by this.

4) Services and startup

I try to disable as many services that is possible or set them to start manual. Services eat memory and CPU-time.

I continually check msconfig.exe (or registry) to sanitize startup programs. More startup-programs makes your computer boot slower.

5) Programs

I try to keep my program list clean. If I do not use a program I remove it. You never know what services and resources a program uses.

If I want to check stuff out I do that in a virtual machine instead of my ”production machine”. It is very handy to have some lab virtual machines if you are a software developer.

6) Useful free programs

Image Resizer Powertoy Clone for Windows
xplorer² (file manager)
Putty (ssh)
WinSCP (moving files with ftp/sftp)
CDBurnerXP
K-lite codec pack (media playing codecs)
Avast antivirus
Filezilla (ftp)
uTorrent
CutePDF Writer
DAEMON Tools Lite
OpenOffice
Firefox
7-zip (file archiver for zip, rar…)
Notepad++ (text editor)

Felaktigt certifikat för mail på yahoo.se vid pop/smtp hämtning

Om du har ett mailkonto på username@yahoo.se och vill kolla din mail med pop/stmp så kan du stöta på problem. Jag har den senaste timmen försökt felsöka varför mailklienten ”Windows Live Mail” spottar ut sig ett felmeddelande om att certifikatet är felaktigt. I bilden nedan så ser du felmeddelandet man får då man synkroniserar mailen (windows 7 x86). Felet beror på att servernamnet som man angett inte stämmer överens med det servernamn som finns i SSL-certifikatet på mailservern.

Yahoo help så kan man läsa att man ska använda pop.mail.yahoo.se samt smtp.mail.yahoo.se. Dessa är däremot bara redirects till engelska mailservrar.

C:\Users\Övriga>ping pop.mail.yahoo.se

Pinging pop1.mail.vip.ukl.yahoo.com [217.146.176.233] with 32 bytes of data:
Reply from 217.146.176.233: bytes=32 time=199ms TTL=52
Reply from 217.146.176.233: bytes=32 time=230ms TTL=52
Reply from 217.146.176.233: bytes=32 time=230ms TTL=52
Reply from 217.146.176.233: bytes=32 time=130ms TTL=52

Ping statistics for 217.146.176.233:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 130ms, Maximum = 230ms, Average = 197ms

C:\Users\Övriga>ping smtp.mail.yahoo.se

Pinging smtp2.mail.vip.ukl.yahoo.com [77.238.184.81] with 32 bytes of data:
Reply from 77.238.184.81: bytes=32 time=166ms TTL=52
Reply from 77.238.184.81: bytes=32 time=180ms TTL=52
Reply from 77.238.184.81: bytes=32 time=202ms TTL=52

Ping statistics for 77.238.184.81:
    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 166ms, Maximum = 202ms, Average = 182ms

Om man kollar certifikatet för dessa servrar så ser det ut enligt följande:

Certifikatet är alltså utfärdat till pop.mail.yahoo.co.uk medans vi använder pop.mail.yahoo.se och då blir det mismatch mellan dessa. Det är alltså de engelska servernamnen som svenska @yahoo.se kunder ska använda för att slippa få felmeddelande angående certifikat. Efter att jag bytt mailservrar till dessa så har det fungerat felfritt. I övrigt så är det samma inställningar med ssl etc. som anges på yahoos hemsida.

Pop och stmp servrar för svenska @yahoo.se mailkunder
Pop: pop.mail.yahoo.co.uk
Smtp: smtp.mail.yahoo.co.uk

Hoppas att detta hjälper fler med samma problem och att yahoo.se uppdaterar sina hjälpsidor.

How to monitor hard drive temperature with MRTG and FreeBSD

I really love to monitor my servers, so why shouldn’t I also monitor the temperatures of my hard drives? In my mind a cooler hard drive lives longer than a hot one. However, the google paper on failure trends of hard drives says that the hard drive temperatures doesn’t have an impact on a hard drives life length. But I want things to run cool in my server so here is how I monitor the hard drives with mrtg and FreeBSD.

To be able to get the hard drives temperatures we have to install SmartMonTools.

The smartmontools package contains two utility programs (smartctl and smartd) to control and monitor storage systems using the Self-Monitoring, Analysis and Reporting Technology System (SMART) built into most modern ATA and SCSI harddisks. In many cases, these utilities will provide advanced warning of disk degradation and failure.

Install SmartMonTools
# cd /usr/ports/sysutils/smartmontools
# make install clean

Check the temperature of the drives that you want to monitor
# smartctl -a /dev/ad4 | grep Temperature_Celsius
194 Temperature_Celsius 0×0022 113 103 000 Old_age Always – 34
# smartctl -a /dev/ad6 | grep Temperature_Celsius
194 Temperature_Celsius 0×0022 148 091 000 Old_age Always – 30

Create a script called disktemp.sh that outputs the temperatures in a Mrtg friendly way.

#!/bin/sh
/usr/local/sbin/smartctl -a /dev/ad6 | grep Temperature | awk '{print $10}' | tail -n 1
/usr/local/sbin/smartctl -a /dev/ad4 | grep Temperature | awk '{print $10}' | tail -n 1
echo "A long time"
echo ""

Then create a mrtg cfg file called disktemp.cfg:

### Global Config Options
WorkDir: /home/www/mrtg
Options[_]: growright, bits
EnableIPv6: no
Language: swedish

# Sysload
Target[disktemp]: `/usr/local/etc/mrtg/disktemp.sh`
MaxBytes[disktemp]: 100
Options[disktemp]: integer,gauge,nopercent
YLegend[disktemp]: Temp (C)
ShortLegend[disktemp]: (C)
Legend1[disktemp]: /dev/ad4
Legend2[disktemp]: /dev/ad6
LegendI[disktemp]: /dev/ad4
LegendO[disktemp]: /dev/ad6
Title[disktemp]: Hard drive Temperature
PageTop[disktemp]: 

Hard drive temperature

Run mrtg (a couple of times)
/usr/local/bin/mrtg /usr/local/etc/mrtg/disktemp.cfg

Check If everything seems to be working. If OK then add this to crontab…

The result should be looking like this (in your language):

Nagios plugin for checking ping in bash

Everyone that uses Nagios knows about the basic check_ping plugin. However, today I needed a light version in bash with the same functionality that its easy to modify…

The result is seen below. My Nagios ping-plugin checks the rtt avg time against the treshold values for critical and warning. I never bothered to check for packet losses because that wasn’t the purpose for this script. It only checks ping avg time but could easily be customized to check other things as well.

nagios-check-ping.sh

#!/bin/bash

# This script pings a host and compares critical and warning tresholds against avg rtt (ms)
# Syntax: nagios-check-ping.sh HOST CRITICAL WARNING
# Example: nagios-check-ping.sh www.sunet.se 10 20

if [ ! -n "$1" ]
then
	echo "UNKNOWN: Missing argument HOSTNAME..."
	exit 3
fi   

if [ ! -n "$2" ]
then
	echo "UNKNOWN: Missing argument WARNING..."
	exit 3
fi   

if [ ! -n "$3" ]
then
	echo "UNKNOWN: Missing argument CRITICAL..."
	exit 3
fi   

AVG=`ping -n -c 5 $1 | awk -F/ '/^rtt/ { print $5 }' | awk -F '.' '{ print $1; }'`

if [ ! -n "$AVG" ]
then
	echo "CRITICAL: Error pinging"
	exit 2
elif [ $AVG -le "$2" ]
then
	SC="OK"
	EX=0
elif [ $AVG -le "$3" ]
then
	SC="WARNING"
	EX=1
else
	SC="CRITICAL"
	EX=2
fi

echo "$SC: Average response time is $AVG ms"
exit $EX

Run it like this:
> nagios-check-ping.sh www.sunet.se 10 20

Example output:
WARNING Average response time is 20 ms