Index: /branches/1.0/web/addons/job_monarch/libtoga.php
===================================================================
--- /branches/1.0/web/addons/job_monarch/libtoga.php	(revision 873)
+++ /branches/1.0/web/addons/job_monarch/libtoga.php	(revision 874)
@@ -598,10 +598,4 @@
     }
 
-    function getUsingFQDN()
-    {
-        $handler = $this->xmlhandler;
-        return $handler->getUsingFQDN();
-    }
-
     function getMetrics()
     {
@@ -649,4 +643,10 @@
         $handler = $this->xmlhandler;
         return $handler->isJobmonRunning();
+    }
+
+    function makeHostname( $ahost, $adomain )
+    {
+        $handler = $this->xmlhandler;
+        return $handler->makeHostname( $ahost, $adomain );
     }
 }
@@ -658,20 +658,15 @@
     function TorqueXMLHandler( $clustername )
     {
-        $this->jobs        = array();
-        $this->clusters     = array();
+        $this->jobs          = array();
+        $this->clusters      = array();
         $this->nodes         = array();
-        $this->metrics      = array();
+        $this->metrics       = array();
         $this->heartbeat     = array();
         $this->down_nodes    = array();
-        $this->offline_nodes    = array();
-        $this->clustername    = $clustername;
-        $this->proc_cluster = null;
+        $this->offline_nodes = array();
+        $this->clustername   = $clustername;
+        $this->proc_cluster  = null;
         $this->proc_hostname = null;
-        $this->fqdn        = 1;
-    }
-
-    function getUsingFQDN()
-    {
-        return $this->fqdn;
+        $this->fqdn          = array();
     }
 
@@ -705,7 +700,21 @@
     }
 
-    function makeHostname( $thostname, $tdomain=null )
-    {
-        if( $this->fqdn && isset( $tdomain ) )
+    function isFqdn( $somehost )
+    {
+        $chr_count = count_chars( $somehost );
+        $dot_count = $chr_count[ ord('.') ];
+
+        if( $dot_count > 1 )
+        {
+            return true;
+        }
+        return false;
+    }
+
+    function makeHostname( $thostname, $tdomain )
+    {
+        $mhost = $thostname;
+
+        if( ( $this->fqdn[ $thostname ] === true ) && isset( $tdomain ) && ( $tdomain !== '' ) )
         {
             if( strpos( $thostname, $tdomain ) === false )
@@ -713,12 +722,4 @@
                 $mhost = $thostname . '.' . $tdomain;
             } 
-            else
-            {
-                $mhost = $thostname;
-            }
-        }
-        else
-        {
-            $mhost = $thostname;
         }
 
@@ -761,4 +762,16 @@
             $hostname = $attrs['NAME'];
             $this->proc_hostname = $hostname;
+
+            if( $this->isFqdn( $hostname ) === true )
+            {
+                $host_fields = explode( '.', $hostname );
+                $shorthost   = $host_fields[0];
+
+                $this->fqdn[ $shorthost ] = true;
+            }
+            else
+            {
+                $this->fqdn[ $hostname ] = false;
+            }
 
             # Pseudo metrics - add useful HOST attributes like gmond_started & last_reported to the metrics list:
@@ -804,5 +817,5 @@
             {
                 $this->heartbeat['time'] = $attrs['VAL'];
-                return;
+                return null;
             }
             else if( strpos( $attrs['NAME'], 'zplugin_monarch_down' ) !== false )
@@ -811,12 +824,12 @@
 
                 $nodes_down    = array();
-                $down_domain    = null;
+                $down_domain   = null;
 
                 foreach( $fields as $f )
                 {
-                    $togavalues    = explode( '=', $f );
+                    $togavalues  = explode( '=', $f );
 
                     $toganame    = $togavalues[0];
-                    $togavalue    = $togavalues[1];
+                    $togavalue   = $togavalues[1];
 
                     if( $toganame == 'nodes' )
@@ -837,5 +850,5 @@
                         if( !isset( $this->down_nodes['heartbeat'] ) )
                         {
-                            $this->down_nodes[$togavalue]    = array( $nodes_down, $down_domain );
+                            $this->down_nodes[$togavalue] = array( $nodes_down, $down_domain );
                         }
                     }
@@ -845,15 +858,15 @@
             else if( strpos( $attrs['NAME'], 'zplugin_monarch_offline' ) !== false )
             {
-                $fields        = explode( ' ', $attrs['VAL'] );
-
-                $nodes_offline    = array();
-                $offline_domain    = null;
+                $fields         = explode( ' ', $attrs['VAL'] );
+
+                $nodes_offline  = array();
+                $offline_domain = null;
 
                 foreach( $fields as $f )
                 {
-                    $togavalues    = explode( '=', $f );
-
-                    $toganame    = $togavalues[0];
-                    $togavalue    = $togavalues[1];
+                    $togavalues = explode( '=', $f );
+
+                    $toganame   = $togavalues[0];
+                    $togavalue  = $togavalues[1];
 
                     if( $toganame == 'nodes' )
@@ -895,6 +908,6 @@
                     $togavalues = explode( '=', $f );
 
-                    $toganame = $togavalues[0];
-                    $togavalue = $togavalues[1];
+                    $toganame   = $togavalues[0];
+                    $togavalue  = $togavalues[1];
 
                     if( $toganame == 'nodes' )
@@ -929,84 +942,52 @@
                 }
 
-                if( isset( $this->jobs[$jobid]['nodes'] ) )
-                {
-                    $nr_nodes = count( $this->jobs[$jobid]['nodes'] );
+            }
+            return;
+        }
+    }
+
+    function finishUp( )
+    {
+        $nodes    = $this->nodes;
+
+        foreach( $this->jobs as $jobid => &$jobattrs )
+        {
+            if( isset( $this->jobs[$jobid]['nodes'] ) )
+            {
+                $nr_nodes = count( $this->jobs[$jobid]['nodes'] );
         
-                    if( $this->jobs[$jobid]['status'] == 'R' )
+                if( $this->jobs[$jobid]['status'] == 'R' )
+                {
+                    foreach( $this->jobs[$jobid]['nodes'] as $node )
                     {
-
-                        if( isset( $this->jobs[$jobid]['domain'] ) )
+                        $domain = $this->jobs[$jobid]['domain'];
+                        $host   = $this->makeHostname( $node, $domain );
+
+                        if( !isset( $nodes[$host] ) )
                         {
-                            $domain        = $this->jobs[$jobid]['domain'];
-                            $domain_len    = 0 - strlen( $domain );
-
-                            $first_host    = key( array_slice($this->nodes, 0, 1, true) );
-
-                            // Let's see if Ganglia use's FQDN or short hostnames
-                            //
-                            if( strpos( $first_host, $domain ) === false )
-                            {
-                                $this->fqdn    = 0;
-                            }
+                            $my_node = new NodeImage( $this->proc_cluster, $host );
                         }
                         else
                         {
-                            $this->fqdn    = 0;
+                            $my_node = $nodes[$host];
                         }
 
-                        foreach( $this->jobs[$jobid]['nodes'] as $node )
+                        if( !$my_node->hasJob( $jobid ) )
                         {
-
-                            // Only add domain name to the hostname if Ganglia is doing that too
-                            //
-                            if( $this->fqdn && isset( $this->jobs[$jobid]['domain'] ) )
+                            if( isset( $this->jobs[$jobid]['ppn'] ) )
                             {
-                                if( strpos( $node, $domain ) === false )
-                                {
-                                    $host = $node. '.'.$domain;
-                                } 
-                                else
-                                {
-                                    $host = $node;
-                                }
+                                $my_node->addJob( $jobid, ((int) $this->jobs[$jobid]['ppn']) );
                             }
                             else
                             {
-                                $host    = $node;
+                                $my_node->addJob( $jobid, 1 );
                             }
-
-                            if( !isset( $this->nodes[$host] ) )
-                            {
-                                $my_node = new NodeImage( $this->proc_cluster, $host );
-                            }
-                            else
-                            {
-                                $my_node = $this->nodes[$host];
-                            }
-
-                            if( !$my_node->hasJob( $jobid ) )
-                            {
-                                if( isset( $jobs[$jobid]['ppn'] ) )
-                                {
-                                    $my_node->addJob( $jobid, ((int) $jobs[$jobid]['ppn']) );
-                                }
-                                else
-                                {
-                                    $my_node->addJob( $jobid, 1 );
-                                }
-                            }
-
-                            $this->nodes[$host] = $my_node;
                         }
+
+                        $nodes[$host] = $my_node;
                     }
                 }
             }
-            return;
-        }
-    }
-
-    function finishUp( )
-    {
-        $nodes    = $this->nodes;
+        }
 
         if( sizeof( $this->down_nodes ) > 0 )
@@ -1490,5 +1471,5 @@
     function getNodes()
     {
-        if( $this->nodes== null )
+        if( $this->nodes === null )
         {
             $this->checkParse();
Index: /branches/1.0/web/addons/job_monarch/overview.php
===================================================================
--- /branches/1.0/web/addons/job_monarch/overview.php	(revision 873)
+++ /branches/1.0/web/addons/job_monarch/overview.php	(revision 874)
@@ -55,5 +55,4 @@
 $gnodes    = $data_gatherer->getNodes();
 $cpus      = $data_gatherer->getCpus();
-$use_fqdn  = $data_gatherer->getUsingFQDN();
 
 //print_r( $gnodes );
@@ -467,17 +466,8 @@
                     $running_name_nodes[] = $tempnode;
 
+                    $hostnode = $data_gatherer->makeHostname( $tempnode, $jobs[$jobid]['domain'] );
+
                     if( isset( $hostname ) && $hostname != '' ) 
                     {
-                        $domain_len     = 0 - strlen( $jobs[$jobid]['domain'] );
-                        $hostnode     = $tempnode;
-
-                        if( $use_fqdn == 1)
-                        {
-                            if( substr( $hostnode, $domain_len ) != $jobs[$jobid]['domain'] ) 
-                            {
-                                $hostnode = $hostnode. '.'. $jobs[$jobid]['domain'];
-                            }
-                        }
-
                         if( $hostname == $hostnode ) 
                         {
@@ -648,8 +638,6 @@
                         foreach( $jobs[$jobid]['nodes'] as $shortnode ) 
                         {
-                            if( $use_fqdn == 1)
-                            {
-                                $mynode     = $shortnode.".".$jobs[$jobid]['domain'];
-                            }
+                            $domain         = $jobs[$jobid]['domain'];
+                            $mynode         = $data_gatherer->makeHostname( $shortnode, $domain );
                             $myhost_href    = "./?c=".$clustername."&h=".$mynode;
                             $mynodehosts[]  = "<A HREF=\"".$myhost_href."\">".$shortnode."</A>";
@@ -837,13 +825,6 @@
             foreach ( $hosts_up as $host ) 
             {
-                $domain_len         = 0 - strlen( $domain );
-
-                if( $use_fqdn )
-                {
-                    if( substr( $host, $domain_len ) != $domain ) 
-                    {
-                        $host         = $host . '.' . $domain;
-                    }
-                }
+                $host             = $data_gatherer->makeHostname( $host, $domain );
+
                 $cpus             = 0;
 
