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

    Issue with creating hooks

    Scheduled Pinned Locked Moved Unsolved
    FOG Problems
    2
    8
    780
    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.
    • F
      FlareImp
      last edited by

      Fog 1.5.9
      Ubuntu 22.04

      I’m trying to make a custom hook to add Bios Version to the Host Management Page but am running into some issues. If i set any of the existing hooks from ‘public $active = false’ to ‘public $active = true’ all I get is a column that shows a $. So if I was to enable ‘addhostserial.hook.php’ I would get a column that says ‘$serial’ rather than the actual serial number of the computer.

      F 1 Reply Last reply Reply Quote 0
      • F
        FlareImp @FlareImp
        last edited by

        Any ideas on this? I have still been unable to locate the issue.

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

          @FlareImp While I’ve not been involved in the code in a bit I think, possibly, it might help to see the code you currently have?

          Otherwise you’re essentially asking us to make the hook for you?

          Not trying to sound rude or anything, but if you’ve been working on it, maybe providing the code would be a good start, and a help for others who may want to do the same thing and could help?

          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

          F 1 Reply Last reply Reply Quote 0
          • F
            FlareImp @Tom Elliott
            last edited by

            @Tom-Elliott I am not asking for anyone to make anything for me. The hooks I am referring to are already listed in the hooks directory. no of them work except for the VNC one which we don’t use. Below is the serial hook code.

            <?php
            /**
             * The host serial hook.
             *
             * PHP version 5
             *
             * @category AddHostSerial
             * @package  FOGProject
             * @author   Tom Elliott <tommygunsster@gmail.com>
             * @author   Greg Grammon <nah@nah.com>
             * @license  http://opensource.org/licenses/gpl-3.0 GPLv3
             * @link     https://fogproject.org
             */
            /**
             * The host serial hook.
             *
             * @category AddHostSerial
             * @package  FOGProject
             * @author   Tom Elliott <tommygunsster@gmail.com>
             * @author   Greg Grammon <nah@nah.com>
             * @license  http://opensource.org/licenses/gpl-3.0 GPLv3
             * @link     https://fogproject.org
             */
            class AddHostSerial extends Hook
            {
                /**
                 * The name of the hook.
                 *
                 * @var string
                 */
                public $name = 'AddHostSerial';
                /**
                 * The description of the hook.
                 *
                 * @var string
                 */
                public $description = 'Adds host serial to the host lists';
                /**
                 * Is the hook active of not.
                 *
                 * @var bool
                 */
                public $active = false;
                /**
                 * Initializes object.
                 *
                 * @return void
                 */
                public function __construct()
                {
                    parent::__construct();
                    self::$HookManager
                        ->register(
                            'HOST_DATA',
                            array(
                                $this,
                                'hostData'
                            )
                        )
                        ->register(
                            'HOST_HEADER_DATA',
                            array(
                                $this,
                                'hostTableHeader'
                            )
                        );
                }
                /**
                 * The data to alter.
                 *
                 * @param mixed $arguments The items to alter.
                 *
                 * @return void
                 */
                public function hostData($arguments)
                {
                    global $node;
                    if ($node != 'host') {
                        return;
                    }
                    $arguments['templates'][] = '${sysserial}';
                    $arguments['attributes'][] = array(
                        'class' => 'c',
                        'width' => '20',
                    );
                    $items = $arguments['data'];
                    $hostnames = array();
                    foreach ((array)$items as &$data) {
                        $hostnames[] = $data['host_name'];
                        unset($data);
                    }
                    Route::listem(
                        'host',
                        'name',
                        false,
                        array('name' => $hostnames)
                    );
                    $Hosts = json_decode(
                        Route::getData()
                    );
                    $Hosts = $Hosts->hosts;
                    foreach ((array)$Hosts as &$Host) {
                        $arguments['data'][$i]['serial'] = $Host
                            ->inventory
                            ->sysserial;
                        unset($Host);
                    }
                    unset($Hosts);
                }
                /**
                 * Alter the table header data.
                 *
                 * @param mixed $arguments The arguments to alter.
                 *
                 * @return void
                 */
                public function hostTableHeader($arguments)
                {
                    global $node;
                    if ($node != 'host') {
                        return;
                    }
                    $arguments['headerData'][] = _('Serial');
                }
            }
            
            
            F 1 Reply Last reply Reply Quote 0
            • F
              FlareImp @FlareImp
              last edited by

              The BIOS Hook is one I was working on but I first need to figure out why the ones that were already made aren’t working before I can try testing my own.

              F 1 Reply Last reply Reply Quote 0
              • F
                FlareImp @FlareImp
                last edited by

                This is what is shown when I enable the hook.
                Sys#.png

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

                  @FlareImp can you change the ‘serial’ to ‘sysserial’ in this line?

                              $arguments['data'][$i]['serial'] = $Host
                                  ->inventory
                                  ->sysserial;
                  

                  Making it:

                              $arguments['data'][$i]['sysserial'] = $Host
                                  ->inventory
                                  ->sysserial;
                  

                  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

                  F 1 Reply Last reply Reply Quote 0
                  • F
                    FlareImp @Tom Elliott
                    last edited by

                    @Tom-Elliott That did not have an impact. still seeing ${serial} on the host list. If it helps I am also seeing at the bottom of my host management page

                    ${pingstatus} ${host_name} ${deployed} ${image_name} ${serial}

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

                    156

                    Online

                    12.0k

                    Users

                    17.3k

                    Topics

                    155.2k

                    Posts
                    Copyright © 2012-2024 FOG Project