Issue with creating hooks
-
Fog 1.5.9
Ubuntu 22.04I’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.
-
Any ideas on this? I have still been unable to locate the issue.
-
@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?
-
@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'); } }
-
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.
-
This is what is shown when I enable the hook.
-
@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;
-
@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}