Pages

Friday, September 7, 2012

Notion Status-bar-display

In the last few days I fiddled with notion and its status-bar. I was looking in to displaying various things in the taskbar at the bottom of the screen.

As I run notion on my laptop, I wanted an easy way to know my IP-address among other things.

The first thing to cross my mind was adopting the battery-display and including a method to display the capacity of all batteries in the system, as well as other information.
Like power consumption and remaining running time.

I developed 3 small Perl-scripts doing all the readout and calculation for this task.

battery-percent display (bat-percent.pl)
1:  #!/usr/bin/perl  
2:  # Number of batteries in the system (theoretically)  
3:  my $BatteryCount = 2;  
4:  # Basepath  
5:  my $BatteryPath = "/sys/devices/platform/smapi/BAT";  
6:  my $i=0;  
7:  my $Available=0;  
8:  my $TotalPercent=0;  
9:  while($i < $BatteryCount){  
10:       my $BatPresentPath = $BatteryPath.$i."/installed";  
11:       open PRESENT,"<", $BatPresentPath or die $!;  
12:       my $BatPresent = <PRESENT>;  
13:       close PRESENT;  
14:       chomp $BatPresent;  
15:       if($BatPresent == 1){  
16:            $Available ++;  
17:            my $BatPercentPath = $BatteryPath.$i."/remaining_percent";  
18:            open PERCENT,"<",$BatPercentPath or die $!;  
19:            my $BatPercent = <PERCENT>;  
20:            close PERCENT;  
21:            chomp $BatPercent;  
22:            $TotalPercent = $TotalPercent + $BatPercent;  
23:       }  
24:       $i++;  
25:  }  
26:  my $ResultPercent=0; if($Available > 0){  
27:       $ResultPercent = ($TotalPercent / $Available);  
28:  }  
29:  print $ResultPercent;  

battery-running-time display (bat-time.pl)
1:  #!/usr/bin/perl  
2:  # Number of batteries in the system (theoretically)  
3:  my $BatteryCount = 2;  
4:  # Basepath  
5:  my $BatteryPath = "/sys/devices/platform/smapi/BAT";  
6:  # AC-Adapter  
7:  my $AcAdapterPath = "/sys/devices/platform/smapi/ac_connected";  
8:  open AC,"<",$AcAdapterPath or die $!;  
9:  my $AcOn = <AC>;  
10:  close AC;  
11:  chomp $AcOn;  
12:  my $i=0;  
13:  my $Available=0;  
14:  my $TotalTime=0;  
15:  while($i < $BatteryCount){  
16:       my $BatPresentPath = $BatteryPath.$i."/installed";  
17:       open PRESENT,"<", $BatPresentPath or die $!;  
18:       my $BatPresent = <PRESENT>;  
19:       close PRESENT;  
20:       chomp $BatPresent;  
21:       if($BatPresent == 1){  
22:            my $BatRemainingTime = $BatteryPath.$i."/remaining_running_time_now";  
23:            open TIME,"<",$BatRemainingTime or die $!;  
24:            my $BatTime = <TIME>;  
25:            close TIME;  
26:            chomp $BatTime;  
27:            if(index($BatTime,"not") == -1){  
28:                 $TotalTime = $TotalTime + $BatTime;  
29:            }  
30:       }  
31:       $i++;  
32:  }  
33:  if($AcOn){  
34:       print "AC-Power";  
35:  }else{  
36:       print $TotalTime." min";  
37:  }  

battery-power-consumption display (bat-power.pl)
1:  #!/usr/bin/perl  
2:  # Number of batteries in the system (theoretically)  
3:  my $BatteryCount = 2;  
4:  # Basepath  
5:  my $BatteryPath = "/sys/devices/platform/smapi/BAT";  
6:  my $i=0;  
7:  my $Available=0;  
8:  my $TotalPower=0;  
9:  while($i < $BatteryCount){  
10:       my $BatPresentPath = $BatteryPath.$i."/installed";  
11:       open PRESENT,"<", $BatPresentPath or die $!;  
12:       my $BatPresent = <PRESENT>;  
13:       close PRESENT;  
14:       chomp $BatPresent;  
15:       if($BatPresent == 1){  
16:            my $BatPowerPath = $BatteryPath.$i."/power_now";  
17:            open POWER,"<",$BatPowerPath or die $!;  
18:            my $BatPower = <POWER>;  
19:            close POWER;  
20:            chomp $BatPower;  
21:            if($BatPower < 0){  
22:                 $BatPower = $BatPower * -1;  
23:            }  
24:            $TotalPower = $TotalPower + $BatPower;  
25:       }  
26:       $i++;  
27:  }  
28:  my $ResultPower = sprintf("%.1f",($TotalPower / 1000));  
29:  print $ResultPower;  

Also I constructed a method to display my IP-address or “offline” if the device did not receive an address.

network display (net.pl)
1:  #!/usr/bin/perl  
2:  # Devices to check  
3:  my $Device = $ARGV[0];  
4:  my $IP = `/sbin/ip addr show $Device | grep "inet " | awk '{print \$2}'`;  
5:  chomp $IP;  
6:  if(index($IP,"/")==-1){  
7:       print "offline";  
8:  }else{  
9:       print $IP;  
10:  }  

Finaly I whipped up a smal snippet of bash-code to get a temperature readout from my nVidia graphics-card on my laptop:
1:  nvidia-smi -q | grep -A 1 "Temperature" | grep -m 1 ":" | awk \'{print $3}\'  

Wednesday, August 8, 2012

Moved the blog

I recently figured, I want to have a little more traffic on my own server so I moved the blog over.

New posts will only be released there, and all the old entries have been moved there so you wont miss a thing.

raptor's IT blog

Edit: removed link to my server, see my next post

Friday, June 1, 2012

Getting a Simatic S5 up and running

While cleaning up my storage room, I came across some interesting pieces of hardware.
As I tend to keep almost everything, vastly recognizable as something potentially usable I gathered quit a collection.
So one of the pieces I rediscovered is a gray box with some screws to tap wires in to...
Thoughtfully I kept it in its original cardboard-box and I discovered the instruction-manual along with it.
The piece of plastic turned out to be a Simatic S5 central unit.
As I am not familiar with PLC-systems I spend roughly an hour reading the manual to discover some of the basic functions.
But reading manuals is not quite as fun, as hacking the equipment.

1. Step: Supplying power...

As with most hardware, this system needed a power supply. Unfortunately 24V DC. And 1A under normal load-circumstances.
Neither did I happen to have a 24VDC power-supply,  nor did I have to car-batterys to power the thing up.
So I whipped something up using an old AC-converter found in a box of old discarded Christmas-lights...
The PSU supplied 24V AC. Fortunately I have a box with scrap-parts and some rectifiers. Converting 24V AC to DC was easily done and I spiced the PSU with a capacitor to straighten out the voltage a little.

2. Step: Dry run...

After figuring out the power-supply the system was hooked up.
With the switch of the power-switch the system sprang to life.
But as I am missing a program to run on the hardware, only the self-test was done. It passed and parked the system in idle-mode.

3. Step: Where to go from here...

As everything on the system is proprietary by Simens, I had to stick to the documents available.
Fortunately I found a schematic of the PG-interface (PG standing for the German word "Programmier Gerat", meaning programming-machine or something similar).
I had to discover, that the PG-interface used TTL 15V to 24V signals-levels. Much to much for RS232 found in the serial-connection of a PC. Also the information on the TTL-line are encoded differently. So I had to find a converter.

Fortunately the MAX232 does exactly this, but it only supplies TTL 5V signals.
Since I had already developed something very similar (a AVR-USB-ISP) I considered using this device as a basis for creating a USB-interface for the Simatic.

4. Step: Wait for the hardware-delivery...

After designing the converter, I only need to wait for my hardware-delivery and I will try to code something for this old piece of hardware.

Friday, April 20, 2012

Why Unix is better than Windows

Ever tried to fix a bug on a Windows system?

Like some program you need to run crashes out of the blue without leaving any notice why it did?

I happened to come across this a few times now, and I must say, I like Unix.

Because if this happens to me on Windows, I usually end up spending a lot of my time arguing with some guy at some support-hotline. Or send e-mails with crash-dumps and tons of other stuff. Or have them visit me.

And normally this costs a whole brick-load of Money. Unless the problem is actually a bug and a "luser-issue".

Under Unix this is slightly different.
If a program crashes I tend to use, they normally leave a crash dump by default. Or at least entries in some log-files.

If not, the program can be started with a verbose option. This should finally give a lead what went wrong.

An example: I had problems with one of my servers. This particular system was running an IRC-server (inspircd) and this program was updated recently. Only a minor change, nothing out of the ordinary.

At least it looked like one.

The service was unable to be started after this update. And for added fun, there where no log-entries, or crash dumps.

It just failed silently.

Until the debug mode was switched on. This revealed a missing module.

Closer examination of the package supplied by my distributions showed an option to enable this module. But the flag which should turn this option on, was never read by the package.

Creating my own package, while using the same source-code, I added the missing flags, and everything worked like a charm.

Conclusion: bug-report + patch went out to the maintainer of the package.

Try this with Windows.

Updates on Unix vs Updates on Windows

I like Windows. I really do. It's easy to use, you install stuff rather fast...

If you have the permissions and payed the bills.

Okay, honestly I hate Windows. Partly this is based on my daily routine, working with it and maintaining a few hundred of these damn things.
If you have to do everything by hand, and on every single system you will go mad.

Fortunately there are some tools out there making your life a little easier

First: WSUS, or Windows Server Update Service
This tool-set works as a distribution-point for updates supplied by Microsoft.
You can update a lot of their stuff, but nothing else.


Second: System Center Suite (SCCM, SCOM, SCVMM, DPM & SCSM)
These are System Center Configuration Manager, basically the same as WSUS, but with more options and support for third party stuff.
System Center Operation Manager, for managing permissions and monitoring systems and stuff.
System Center Virtual Machine Manager, for managing your Hyper-V systems, no support for VMWare, or more precisely no working support.
Data Protection Manager, for managing file-servers, local-shares, cloud-storage and backups.
And finally System Center Service Manager, which sounds great, but I am not sure what it actually does.

With these you have the opportunity to do a little bit of management (WSUS) or pay a huge bunch of money to manage every fart of someone, but with about 1 million years of learning how to do so.


So I am stuck with this huge truckload of software, and I don't really want to use it, as it's far to complex for keeping all your software up to date. But I have to go all-in, or stick to WSUS and keep updating all the other programs by hand.

When I want to update the Unix systems I have to work with, this whole procedure gets a lot easier.
The steps are basically:
  1. ssh to the monitoring system
  2. start a .sh script
  3. drink coffee
What the script does is the following stepps:
  1. query DB for unix-hosts
  2. ssh to the host and execute local update
  3. go to 1 until there are no systems left
  4. send e-mail with summary
Until something goes wrong.
Or actually the updates are nearly always a success, at least more often than with Windows.

Monday, March 5, 2012

Fun with VM-Ware

A new week begins, and so does the fun with computer-systems.

As I tend to use a lot of virtualized systems, 'cause they are a lot easier to manage, I tried something new.

Firstofall I need to discrbe the Infrastructure hosting the VMs.
As I manage quite a bunch of systems, a normal VM-host doesn't supply enough power for them all, so I use a clustered version of the VM-ware ESX.
Hardware in this cluster is a bunch of HP-servers, all identical and a bunch of SAN-disks.

As I ran out of power on these systems my first try was to eliminate unused systems.
That cleared up some disk-space, but nearly no CPU or RAM consumption.

The next idea was to suspend systems, not needed during periods of the day. Such as development-servers, as they only need to run at daytime, when the developers actualy work on them.

I setup a timed schedule to suspend them late and power them up again before office-hours.

Okay, that worked.

Still I happened to have a lot of CPU and RAM usage and the system-manager for the cluster still showed warnings about them.

So I went for suspending systems, unused during the day. Like systems only needed for short amounts of time.

My idea was to suspend them via the "suspend when idle" function built into the Windows powermanagement.
That worked. CPU and RAM usage went below threshold and the cluster ran smoothly.

Until the systems happened to be needed again...
Wakeup of them was a problem. Sure hitting the "Resume"-button did work, but who wants to do this for more than a couple of systems.

Lets just put a number, do you want to resume a hundred systems, when they are needed, by hand?

So I went for the "Wake on Lan" option. This stuff actualy works quite well....

If you happen to have hardware-systems...

But you won't power those down...

In VM-Ware this is an entirly different story. WoL does work, but only if you keep the system running idle. If it does WoL works flawlessly, but blocks the CPU and RAM as if it was running full power...

WoL does not work, if the VM is suspended or even shut down.

So I am trying to figure out a way of dooing this by hand.

Thursday, February 16, 2012

SharePoint #2

My list "Why I hate SharePoint" is getting longer by the minute.

Upon moving pages into folders, SharePoint ignores folder-structurs over all.
For example:
"Basesite -> Index"
is displayed correctly.
but, when I create a folder and move the index page into this folder the following is diplayd:
"Basesite -> Index"
instead of
"Basesite -> Folder -> Index"
Okay, I might live with this issue, since in the navigation (which I have to build manualy, 'cause automated navigation is screwed) I am able to correct this issue.

Next I noticed, if I try to change a page title, it get's ignored too.

I tried to use it as a compensation for the broken page-display, but....

I edited the title of a page inside a folder to:
"Foldername - Pagename"
Which is displayed correctly in the page options. But not in the HTML-title-tag.

This is definatly a WTF!

SharePoint, screw you

SharePoint and JavaScript

Today I wanted to edit a Wiki-Page in our company.

Well editing did work finy, up to the point where I wanted to add a JavaScript to a link.

Specifialy a OnClick-event.

First of all SharePoint doesn't support this type of link at all.
The only thing Sharepoint does undestand is "create a link" with some kind of url behind it.

Which will result in a <a href="linkToSite">Text</a> in HTML.

So I went for editing the HTML by myself.
The part where the link is definde was found quickly and the HTML tags for OnClick have been inserted:

HTML code now: <a href="#" OnClick="someJavaScriptStuff">Text</a>

As soon as I closed the HTML-editor on the SharePoint WYSIWYG editor it told me "Some of your HTML might been edited.".
So I reopened the HTML-editor and looked my link up again.

It looked like I left it.

I was like, great, it works.

Next step: Save page.

Okay, hit the link and.... nothing works.

Next step: Reedit page, go into HTML mode and:

THE OnClick-event WAS MISSING!

What on earth was the developer thinking, who implementet such a rule?
Honestly, HTML-Validator passes without errors, and SharePoint deletes this stuff silently?

Friday, February 10, 2012

Dell PowerEdge 1850 + PowerVault 220S

Only a few moments ago I started this blog, and I already feel the need to share something with you.

I started work today and one of my first duties of the day is checking Nagios for failed systems.

First thing I noticed was a critical message of one of the servers I work with.
At second glance it showed: Dell PowerEdge 1850 with attached PowerVault 220S.
And the entire vault is missing from the system.

So what went wrong?

As the vault wasn't even listed in the system properties anymore I thought about somebody accidentally unplugged it. As we use a shared datacentre with a couple of other companies together this could be a possibility.
But I was relieved to discover, that the vault itself was still plugged in correctly and was humming away in idle-mode.

Okay, so something different went wrong.

A close look at the system-logs revealed a reboot in the middle of the night, which is not uncommon for systems with auto updates enabled.

I used Google a bit and hit another blog, describing something very similar to my problem (Nerhood Weblog).

So running some system diagnostics revealed: Dell PERC 3/DC as a RAID controller, managing the vault.

Shutting down the server and doing a cold start didn't solve the problem by the way, it's some sort of crude gamble playing with these devices. Sometime they appear after a reboot, mostly they don't.

Where to go from here? I actually don't know. Since the devices are out of warranty a few years now, I think I'll try to find a replacement for the crappy controller as this seems to be the main source of failure in this case.

If you happen to have these devices lying around, don’t under any circumstances try to use them in this combination. You will fail.

I hope I'll find a fix for this. Somehow.


First post ever

Well hi there.

I finally got the wits to start my own blog.
Well sort of. After all this is Blogger and I only pushed a few buttons.

What to begin with?

My main motivation for creating this blog is my work. As it's somehow a bit frustrating to see hardware die, I wanted to share my knowledge with you. Because mostly hardware doesn't die by itself. Sure there are some incidents you will know about, which are entirely hardware related. But a lot of failures are human intervention.

So this Blog will describe some things, I came to notice.