• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Search Host by Image

    Scheduled Pinned Locked Moved
    General
    2
    4
    1.8k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      AsciiReign
      last edited by

      I tried to modify the fog 0.32 webgui to enable searching for hosts associated with a specified image.
      I managed to display the image in the host search but i still cannot search for the image name.
      I added the changes i made in the files in this post.

      Can anyone point me to what i am missing?
      Maybe this can be useful for other people too.

      fog.main.js
      [CODE]Host Search
      $(‘#host-search’).fogAjaxSearch({
      ‘URL’: ‘ajax/host.search.php’,
      ‘Template’: function(data, i)
      {
      return ‘<tr id="host-’ + data[‘id’] + ‘"><td><input type=“checkbox” name="HID’ + data[‘id’] + ‘" checked=“checked” /></td><td><span class=“icon ping”></span></td><td><a href="?node=host&sub=edit&id=’ + data[‘id’] + ‘" title=“Edit”>’ + data[‘hostname’] + ‘</a></td><td>’ + data[‘mac’] + ‘</td><td>’ + (data[‘ip’] ? data[‘ip’] : ’ ') + ‘</td><td>’ + data[‘image’] + ‘</td><td class=“c”><a href="?node=host&sub=edit&id=’ + data[‘id’] + ‘"><span class=“icon icon-edit” title=“Edit: ’ + data[‘hostname’] + '”></span></a></td></tr>’;
      }
      });[/CODE]

      host.search.include.php
      [PHP] <input id=“host-search” type=“text” value=“<?php echo(_(‘Search’)); ?>” class=“search-input” />

      <form method="POST" name="hosts" action="?node=host">   
          <table width="100%" cellpadding="0" cellspacing="0" id="search-content" border="0">
              <thead>
                  <tr class="header">
                      <td width="22"><input type="checkbox" name="no" checked="checked" /></td>
                      <td width="20"></td>
                      <td><?php print _('Host Name'); ?></td>
                      <td width="120"><?php print _('MAC'); ?></td>
                      <td width="120"><?php print _('IP Address'); ?></td>
                      <td width="120"><?php print _('Host Image'); ?></td>
                      <td class="c" width="40"><?php print _('Edit'); ?></td>
                  </tr>
              </thead>[/PHP]
      

      host.search.php
      [PHP]$host = $arHosts[$i];
      $mac = $host->getMAC();
      $strMac = “”;
      $Image = $host->getImage();
      if ( $Image != null ) $strImage = $Image->getName();
      else ($strImage = “”);
      if ( $mac != null ) $strMac = $mac->getMACWithColon();

              // Minimum fields
              $x = array(   
                      'id'        =>    $host->getID(),
                      'hostname'    =>    $host->getHostname(),
                      'image'        =>  $strImage,
                      'mac'        =>    $strMac
                      );
              [/PHP]
      
      1 Reply Last reply Reply Quote 0
      • Tom ElliottT
        Tom Elliott
        last edited by

        This is really very simple to do. Rather than editing multiple files you can do the lookup in one spot.

        The SQL Code should look something along the lines of:
        [php]‘SELECT hosts.* FROM hosts
        LEFT OUTER JOIN
        (SELECT * FROM hostMAC WHERE hmMAC LIKE “%${keyword}%”) hostMAC
        ON (hmHostID=hostID)
        LEFT OUTER JOIN
        inventory
        ON (iHostID=hostID)
        LEFT OUTER JOIN
        (SELECT * FROM groups INNER JOIN groupMembers ON (gmGroupID=groupID) WHERE groupName LIKE “%${keyword}%” OR groupDesc LIKE “%${keyword}%”) groupMembers
        ON (gmHostID=hostID)
        LEFT OUTER JOIN
        images
        ON (hostImage=imageID)
        WHERE
        hostID LIKE “%${keyword}%” OR
        hostName LIKE “%${keyword}%” OR
        hostDesc LIKE “%${keyword}%” OR
        hostIP LIKE “%${keyword}%” OR
        hostMAC LIKE “%${keyword}%” OR
        groupID LIKE “%${keyword}%” OR
        groupName LIKE “%${keyword}%” OR
        groupDesc LIKE “%${keyword}%” OR
        imageName LIKE “%${keyword}%” OR
        imageDesc LIKE “%${keyword}%” OR
        iSysserial LIKE “%${keyword}%” OR
        iCaseserial LIKE “%${keyword}%” OR
        iMbserial LIKE “%${keyword}%” OR
        iPrimaryUser LIKE “%${keyword}%” OR
        iOtherTag LIKE “%${keyword}%” OR
        iOtherTag1 LIKE “%${keyword}%” OR
        iSysman LIKE “%${keyword}%” OR
        iSysproduct LIKE “%${keyword}%”
        GROUP BY
        hostID DESC’;[/php]
        I’m currently looking up the code portion needed for 0.32.

        Lines 427 through 450 in /var/www/{FOGWEB}/lib/fog/HostManager.class.php appear to be where the sql is getting the data.

        You’ll have to adjust my code above to match that in the file so things actually work for you.

        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

        1 Reply Last reply Reply Quote 0
        • A
          AsciiReign
          last edited by

          It worked. Thanks.

          /var/www/{FOGWEB}/lib/fog/HostManager.class.php:
          [PHP]
          …
          left outer join
          inventory
          on ( iHostId = hostID )
          left outer join
          images
          on ( hostImage = imageID )

          WHERE
          hostName like ‘%" . $this->db->escape($crit) . "%’ or
          hostDesc like ‘%" . $this->db->escape($crit) . "%’ or
          hostIP like ‘%" . $this->db->escape($crit) . "%’ or
          hostMAC like ‘%" . $this->db->escape($crit) . "%’ or
          hmMAC like ‘%" . $this->db->escape($crit) . "%’ or
          iSysSerial like ‘%" . $this->db->escape($crit) . "%’ or
          iPrimaryUser like ‘%" . $this->db->escape($crit) . "%’ or
          iOtherTag like ‘%" . $this->db->escape($crit) . "%’ or
          iOtherTag1 like ‘%" . $this->db->escape($crit) . "%’ or
          iSysman like ‘%" . $this->db->escape($crit) . "%’ or
          imageName like ‘%" . $this->db->escape($crit) . "%’ or
          iSysproduct like ‘%" . $this->db->escape($crit) . "%’
          GROUP BY
          hostID " . $this->getSortingOptions( $sortingOpts );
          …
          [/PHP]

          1 Reply Last reply Reply Quote 0
          • Tom ElliottT
            Tom Elliott
            last edited by

            Thank you for posting the code. I’d have done it, but I’m more focused on 0.33 so thank you for taking the time and posting the code you used.

            Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

            Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

            Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post

            278

            Online

            12.0k

            Users

            17.3k

            Topics

            155.2k

            Posts
            Copyright © 2012-2024 FOG Project