"; echo ""; echo ""; echo ""; // define vars $ldaphost = "zlmservername"; // zlm server $ldapport = 10389; $ldapuser = "cn=admin,o=system"; $ldappwd = "zlmadministratorpassword"; // zlm Administrator password $ldapbase = "o=cell"; // device parameters $ldapdevfilt = "objectclass=nrmDevice"; $ldapdevattr = array("dn", "nrmName", "nrmOS", "nrmGroupList"); // association parameters $ldapassfilt = "(&(objectclass=nrmAssociation) (nrmAssocContentType=Bundle)(nrmAssocContent=*))"; $ldapassattr = array("dn", "nrmAssocContent"); // bundle parameters $ldapbunfilt = "(&(|(objectclass=nrmBundle) (objectclass=nrmBundleGroup)) (nrmName=$bundle))"; $ldapbunattr = array("dn", "nrmXmlData"); // background colors $ok="bgcolor=#33FF33"; $warn="bgcolor=#FFFF33"; $notok="bgcolor=#FF3333"; $unknown="bgcolor=#FFCC33"; // zlm postgresql informations $pghost = "zlmservername"; // zlm server $pgdb = "zenworks"; $pguser = "zenadmin"; $pgpwd = "zlmpostgresqlpassword"; // postgresql password from /etc/opt/novell/zenworks/serversecret $pgquery = "SELECT alias, last_contact FROM zen_device"; $pginst = "select zen_device.hostname from zen_device inner join bundles on zen_device.bwhash=bundles.whash inner join installed_bundles on bundles.inbndlid=installed_bundles.inbndlid inner join zen_bundle on installed_bundles.bndlid=zen_bundle.bndlid where zen_bundle.name="; // timezone $timezone = "Europe/Vienna"; // tolerance for the zlm last contact row $zlmlastcontacttol = 21600; $timeoffsetpg = 3600; // connecting to LDAP $ldapconn = ldap_connect($ldaphost, $ldapport) or die("LDAP: could not connect to $ldaphost:$ldapport"); // switching to ldap version 3 for tls $ldapv3 = ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3); if (!$ldapv3) { ldap_close($ldapconn); die("LDAP: could not switch to ldap protocol v3"); } // activating tls // this needs TLS_REQCERT to be set to never in /etc/openldap/ldap.conf $ldaptls = ldap_start_tls($ldapconn); if (!$ldaptls) { ldap_close($ldapconn); die("LDAP: could not start tls"); } // binding to ldap $ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappwd); // verify binding if (!$ldapbind) { ldap_close($ldapconn); die("LDAP: bind failed for user $ldapuser"); } // getting deployed bundle version if (!isset($version)) { // first do a ldap search for the bundle $results = ldap_search($ldapconn, $ldapbase, $ldapbunfilt, $ldapbunattr); $bundledata = ldap_get_entries($ldapconn, $results); // create new dom object and load ldap search results $bundlexmldata = new DomDocument; $bundlexmldata->loadXML($bundledata[0]["nrmxmldata"][0]); // get bundle dn $bundledn = $bundledata[0]["dn"]; // select the value from the xml tag Version $version = simplexml_import_dom($bundlexmldata)->Version[0]; } // ldap search for associations $results = ldap_search($ldapconn, $ldapbase, $ldapassfilt, $ldapassattr); ldap_sort($ldapconn, $results, "nrmAssocContent"); $assoc = ldap_get_entries($ldapconn, $results); if ($bundle) { echo "

ZLM Reporting - Bundle $bundle - Version $version

"; } else { echo "

ZLM Reporting:

"; } // now build the drop down list with all assigned bundles echo "
"; echo ""; echo ""; echo ""; echo "
Select a Bundle
"; echo "

"; // if a bundle is selected build the html table if ($bundle) { // ldap search for device $results = ldap_search($ldapconn, $ldapbase, $ldapdevfilt, $ldapdevattr); ldap_sort($ldapconn, $results, "nrmName"); $devices = ldap_get_entries($ldapconn, $results); // put all devices and their distributions into a hash for // requesting the os a little bit later $hashdevices = array(); $naghoststats=array(); $nagsvcstats=array(); for ($j = 0; $j < $devices["count"]; $j++) { $devname = $devices[$j]["nrmname"][0]; $hashdevices["$devname"] = substr($devices[$j]["nrmos"][0],2,20); } // get all last contact information from the zlm postgresql database $pgconn = pg_connect("host=$pghost dbname=$pgdb user=$pguser password=$pgpwd") or die('PostgreSQL: could not connect: ' . pg_last_error()); $pgresult = pg_query($pgconn, $pgquery) or die('PostgreSQL: query failed: ' . pg_last_error()); while ($pgrow = pg_fetch_row($pgresult)) { $hashdevices["$pgrow[0]-lc"] = $pgrow[1]; } pg_close($pgconn); // get the installed bundle list of the zlm database $pgconn = pg_connect("host=$pghost dbname=$pgdb user=$pguser password=$pgpwd") or die('PostgreSQL: could not connect: ' . pg_last_error()); $pgresult = pg_query($pgconn, $pginst . "'" . $bundle . "' AND zen_bundle.version=" . $version . ";") or die('PostgreSQL: query failed: ' . pg_last_error()); $i = 0; while ($pgrow = pg_fetch_row($pgresult)) { $instdevices[$i] = $pgrow[0]; $i++; } pg_close($pgconn); // search for all associations matching that bundle $ldapassfiltbun = "(&(objectclass=nrmAssociation) (nrmAssocContentType=Bundle)(nrmAssocContent=$bundledn))"; $ldapassattrbun = array("dn", "nrmAssocConsumer", "nrmAssocConsumerType"); $results = ldap_search($ldapconn, $ldapbase, $ldapassfiltbun, $ldapassattrbun); $associations = ldap_get_entries($ldapconn, $results); // go through every consumer and check what it is $devicelist = array(); for ($i = 0; $i < $associations["count"]; $i++) { $consumer = $associations[$i]["nrmassocconsumer"]; // get more details of the association as they write for devices, folders, // groups always Server into the consumertype $ldapobjbase = "$consumer[0]"; $ldapobjfilt = "objectClass=*"; $ldapobjattr = array("dn", "nrmObjectType"); // do a ldap read for the consumer object $results = ldap_read($ldapconn, $ldapobjbase, $ldapobjfilt, $ldapobjattr); $assocobjects = ldap_get_entries($ldapconn, $results); $consumertype=" " . implode(" ",$assocobjects[0]["nrmobjecttype"]) ." "; // if object type is a folder add all devices below this folder if (strpos($consumertype, "#Folder ")) { for ($j = 0; $j < $devices["count"]; $j++) { if (strpos($devices[$j]["dn"], $consumer[0])) { $devicelist[] = $devices[$j]["nrmname"][0]; } } // if object type is a group get all members } elseif (strpos($consumertype, "#Device Group ")) { for ($j = 0; $j < $devices["count"]; $j++) { if ($devices[$j]["nrmgrouplist"] = $consumer) { $devicelist[] = $devices[$j]["nrmname"][0]; } } // if object type is a device, add it to the list } elseif (strpos($consumertype, "#Device ")) { $devicelist[] = substr($consumer[0],8,strpos($consumer[0], ',') - 8); } } // delete duplicate devices as bundles can be assigned directly // and through groups or folders, at the end sort the device list $devicelistunique = array_unique($devicelist); sort($devicelistunique); // print html table header echo "

"; echo ""; for ($i = 0; $i < count($devicelistunique); $i++) { echo ""; // collect table data $nr=$i+1; $server = $devicelistunique[$i]; $serveros = " " . $hashdevices["$server"] . " "; // check the zlm last contact time and add the tolerance and set the // color of the cell $serverlastcontact = strtotime($hashdevices["$server-lc"]); if (($serverlastcontact+$zlmlastcontacttol) > time()) { $serverlc = ""; } else { $serverlc = ""; } // check if there is a dot in the device name. If so cut it off // have seen this that sometime edir has the servername with the dns suffix and // the database just contains the servername if (strpos($server, '.')) { $servername = substr($server, 0, strpos($server, '.')); } else { $servername = $server; } // build the string for the installed bundles if (in_array($servername, $instdevices)) { $installed = ""; } else { $installed = ""; } echo "$serverlc$installed"; echo "
ZLM Information
NRServerOSLast ContactInstalled
 " . gmdate("d.m.y H:i", $serverlastcontact+$timeoffsetpg) . "  " . gmdate("d.m.y H:i", $serverlastcontact+$timeoffsetpg) . " YesNo$nr  $server  $serveros