Well, I started last night trying to get my Apache+PHP+MySQL+OpenSSL+IMAP compiled to run on the new X2100. What a nightmare. For some reason some of the software compiled as 32bit, some as 64 bit and nothing would link together right. I ended up putting Sun Studio 11 on the machine and trying it all again. Got OpenSSL, MySQL and IMAP to compile as 64 bit. Then was gettext and libxml2. gettext refuses to do the whole compile as 64 bit. Part of it does 32 bit and I can’t find out where. I keep getting those little “wrong ELF class: ELFCLASS64″ or “wrong ELF class: ELFCLASS32″. I tried striping everything out of my path and environment variables and still does not work. Any one out there know exactly what needs set to make it all 32 or all 64 bit? I found that if I had /usr/ccs/bin in the path that it was trying to use the 32 bit linker, so I had to put /usr/ccs/bin/amd64 before the /usr/ccs/bin. I also added the CFLAGS environment variable of “-xarch=amd64″..

I even tried compiling everything on a Dual Pentium 3 machine (which is not 64 bit) and copying it over, but that failed too.

/Silently goes to bed with head down and wishing I could have afforded a T2000.

Posted by unixwiz, filed under PHP, Random Stuff, Solaris, X2100. Date: April 11, 2006, 10:04 pm | 1 Comment »

I have decided to try and teach my self some java by using the free Sun Java Studio Creator 2 application. (My background is computer hardware engineering, so I never really played with Java while I was going through school. What I did get some what good at was Assembly, C, and Ada. Since I was not in Computer Science but rather in the Engineering school, they did not have us do any Java. Java was considered an elective, and when my time to take electives came around I did a lot of network hardware and network software electives. One of the classes I took was a class on network software programming. Having never done any socket programming before I took this class, it was sort of scary when on the first day the teacher says “your first project is to make a HTTP Proxy server, you have 2 weeks.” Needless to say it was one of the coolest classes I ever took at the university and probably one of the ones I learned the most in.) Anyways, I have decided to see if I can replicate my Syswatch web interface in JSP just as a proof of concept. It will probably take me a while as I said earlier I have 0 java/jsp experience.

99.9% of all the web apps I have written have been done in PHP. I have been using PHP since version 2, when is it called PHP/FI… I wrote a couple of apps that would help manage DNS and DHCP for a department I was working in at the time. We had about 10,000 IP’s and I found the easiest way to keep inventory of them was to build a web based front in to a MySQL DB and have it control BIND and DHCP. Later on I rewrote the entire thing to support dynamic registration of PC’s that the students brought to the dorms. Needless to say, PHP is the language that I use for pretty much any web app I have been doing lately.

So I downloaded Java Studio Creator 2 last night and set it up on my fastest machine (which is running windows at the moment). Installed MySQL and copied over a copy of my Syswatch DB. I have been able to get a table to display some of the content from the database, all with out reading any manuals yet. So we will see how far I can get before I get stuck.

Posted by unixwiz, filed under Java, PHP. Date: February 7, 2006, 8:54 pm | No Comments »

So i previously mentioned that all the current version information is stored in a MySQL database on the main syswatch server. So how does the client code get updated? Pretty easy, each time before the program runs it runs this script to check the version info between the local files and what is on the server.

< ?
mysql_connect("syswatch-server","syswatch") or die(mysql_error());
mysql_select_db("syswatch");
//Get list of files to check to see if they exist
//Get OS so only ones required by this os are downloaded
$OSTYPE=@system("/bin/uname");

$result=mysql_query("select * from versions where os =’ALL’ or os=’$OSTYPE’");
$num=mysql_num_rows($result);
$i=0;
echo "There are $num function files\n";
while ($i < $num ) {
        $File[$i]=mysql_result($result,$i,"function");
        $Version[$i]=mysql_result($result,$i,"version");
        $MD5Sum[$i]=mysql_result($result,$i,"md5file");
       
        $fp = @fopen($File[$i],r);
        if ($fp) {
                //File Exists
                while (!feof($fp)) {
                        $buffer=fgets($fp);
                        if (ereg("//SYSVERSION:",$buffer)) {
                                //Should be a version line explode on the :
                                list($PreHead,$VERSION)=explode(":",$buffer);
                                $VERSION=ereg_replace("\n","",$VERSION);
                                if ("$VERSION" != "$Version[$i]" ) {
                                        echo "$File[$i] is downrev, it is $VERSION, current is $Version[$i]\n";
                                        echo "Downloading new version\n";
                                        //File is downrev, need to get new file
                                        $newfp=fopen("http://syswatch-server:8080/syswatch/$File[$i].txt",r);
                                        fclose($fp);
                                        unlink($File[$i]);
                                        $fp=fopen($File[$i],w);
                                        while (! feof($newfp)) {
                                                $buffernew=fgets($newfp);
                                                fputs($fp,$buffernew);
                                        }
                                        //Check the md5 sum of the file to make sure it has not been changed;
                                        $NewFile=md5_file($File[$i]);
                                        if ($NewFile!=$MD5Sum[$i]) {
                                                //If MD5’s don’t match issue warning and stop.
                                                echo "Local File does not match MD5 of stored function, stopping now\n";
                                                echo "File name: $File[$i]\n";
                                                echo "Local MD5: $NewFile\n";
                                                echo "Store MD5: $MD5Sum[$i]\n";
                                                exit (1);
                                        }
                                }
                                else {
                                        $NewFile=md5_file($File[$i]);
                                        if ($NewFile!=$MD5Sum[$i]) {
                                                //If MD5’s don’t match issue warning and stop.
                                                echo "Local File does not match MD5 of stored function, stopping now\n";
                                                echo "File name: $File[$i]\n";
                                                echo "Local MD5: $NewFile\n";
                                                echo "Store MD5: $MD5Sum[$i]\n";
                                                exit (1);
                                        }
                                        echo "$File[$i] is at current version\n";
                                        fclose($fp);
                                        break;
                                }
                        }
                }
        }
        else {
                //File does not exist, need to download it
                echo "$File[$i] does not exist, downloading now\n";
                $newfp=fopen("http://syswatch-server:8080/syswatch/$File[$i].txt","rb");
                while (!feof($newfp))
                {
                        $contents.=fgets($newfp,1024);
                }
                fclose($newfp);
                $fp2=@fopen($File[$i],"w");
                fwrite($fp2,$contents);
                fclose($fp2);
                $NewFile=md5_file($File[$i]);
                if ($NewFile!=$MD5Sum[$i]) {
                        //If MD5’s don’t match issue warning and stop.
                        echo "Local File does not match MD5 of stored function, stopping now\n";
                        echo "File name: $File[$i]\n";
                        echo "Local MD5: $NewFile\n";
                        echo "Store MD5: $MD5Sum[$i]\n";
                        exit (1);
                }
        }
        $contents="";
        $i++;
}

Posted by unixwiz, filed under PHP, Syswatch. Date: January 23, 2006, 8:47 pm | No Comments »

The second table used, is the uptimes table. This table keeps a list of all the machines with their OS, hardware type and last time they updated.

mysql&>describe uptimes;

+------------+------------+------+-----+---------+-------+
| Field      | Type       | Null | Key | Default | Extra |
+------------+------------+------+-----+---------+-------+
| hostname   | char(255)  |      | PRI |         |       |
| date       | datetime   | YES  |     | NULL    |       |
| timeinsec  | bigint(20) | YES  |     | NULL    |       |
| arch       | char(25)   | YES  |     | NULL    |       |
| osrevision | char(10)   | YES  |     | NULL    |       |
| os         | char(25)   | YES  |     | NULL    |       |
+------------+------------+------+-----+---------+-------+

Basicly the fields are describe what they are used for. I store the machine type in the arch field, I.E. sparc,x86_64,powerpc, x86, etc. Bascily what ever is returned by:

uname -p

The OS Version is what is returned by the :

uname -r

However AIX is weird and will not tell you the real version so on AIX I do the following:

if ($OS=="AIX") {      
     $OSRM=system("/bin/uname -v");      
     $OSRminor=system("/bin/uname -r");    
     $OSRevision="$OSRM.$OSRminor";    
}

The timeinsec field holds the time that the machie updated in seconds. This is used by the web interface to report any machines that have not updated in the last xxx seconds. This table is updated twice a run, once at the begining and once at the end. This table also helps with Sun Patch management which I will describe later.

Posted by unixwiz, filed under PHP, Syswatch. Date: January 10, 2006, 7:13 pm | No Comments »

One of the key tables in my Syswatch program is the versions table. Earlier I showed that it is defined as :

mysql> describe versions;
+----------+-----------+------+-----+---------+-------+
| Field    | Type      | Null | Key | Default | Extra |
+----------+-----------+------+-----+---------+-------+
| function | char(255) | YES  |     | NULL    |       |
| version  | char(10)  | YES  |     | NULL    |       |
| md5file  | char(255) | YES  |     | NULL    |       |
| os       | char(255) | YES  |     | NULL    |       |
+----------+-----------+------+-----+---------+-------+

In this table I store the information about the check scripts that get downloaded by each of the machines I am monitoring. A sample entry might look like this :

+-------------------+---------+----------------------------------+------+
| function          | version | md5file                          | os   |
+-------------------+---------+----------------------------------+------+
| syswatch.main.php | 0.0.39  | d1ec72f86bfa4ad1fae81bcf4c763500 | ALL  |
+-------------------+---------+----------------------------------+------+

In the above example the name of the script is called syswatch.main.php (which happens to be the main program), It is currently at version 0.0.39 (this gets updated every time I update a script. The md5file string contains the md5 signature of the file. This allows my program to check to see if any one has messed with either the local or remote files. The OS field is which hosts should download the files. In this case all hosts need this one, but it may contain SunOS, AIX, Linux, Darwin, etc for other OS’.

The way the program checks for updates is it runs a striped down script that only checks the versions tables and compares it with the local files. Each local file has a string at the top of it that contains a line like this:

//SYSVERSION:0.0.7

The version number is compared to what is in the database, and if it is lower, it downloads the new file and overwrites the old one.

Posted by unixwiz, filed under PHP, Syswatch. Date: January 7, 2006, 11:24 pm | No Comments »

« Previous Entries