How to show inventory of devices on the dashboard page using hooks?
-
Not quite sure if this is the correct forum, but I don’t see any more appropriate categories, so I’ll ask my question here (sry if I missed something):
I’m currently playing around with the (php) code and I was able to pretty much get anything I wanted going. But I seem to have trouble with the following: I want to show the inventory of every device on the dashboard page. I’m not quite sure how to do that though. I have tried several approaches but somehow none of them work (e.g. MySQL query, …). How do I go about when I want to show certain inventory elements of specific devices on the dashboard page, or to be more precise, which classes/functions do I have to call?
Thanks.
Edit: I decided to try to use hooks to solve this problem.
-
You shouldn’t have to make any specific calls, and this is probably better handled by using a hook or a plugin to do what you want.
-
Ok thanks. I’ll have a look those options then.
-
Hmm, am I missing something or why does only the VNC hook work? All other hooks aren’t working when I set
$active = true;
. Btw, I’m using FOG 4700. -
Hooks work off the events they are designed for. For example, the vnc hook affects the host management page off the HOST_DATA event. If HOST_DATA doesn’t exist but the hook is active there isn’t going to be anything that needs alteration.
-
@Tom-Elliott I’ve tried to copy and paste the VNC hook into e.g. AddHostSerial hook, they both use HOST_DATA so they should be interchangeable. Copying VNC code to AddHostSerial didn’t work but for some reason, copying AddHostSerial code to VNC did work. I don’t understand why though.
-
@Tom-Elliott I modified the VNC hook now to represent a minimal (working) example:
class HostVNCLink extends Hook { var $name = 'HostVNCLink'; var $description = 'Adds a "VNC" link to the Host Lists'; var $author = 'Blackout'; var $active = true; function DashboardData($arguments) { if ($_REQUEST['node'] == 'home') { echo 'test'; } } } $HookManager->register('DashboardData', array(new HostVNCLink(), 'DashboardData'));
If I use the exact same code in e.g.
AddHostSerial.hook.php
(with the classnames changed ofc), the hook doesn’t work. This is what I don’t understand. Do I have to register AddHostSerial somewhere for it to work? -
@Tom-Elliott Ok I figured it out. The problem were the comments in the
AddHostSerial.hook.php
:/** @var $name the name of the hook */ public $name = 'AddHostSerial'; /** @var $description the description of what the hook does */ public $description = 'Adds host serial to the host lists'; /** @var $author the author of the hook */ public $author = 'Junkhacker with edits from Tom Elliott'; /** @var $active whether or not the hook is to be running */ public $active = true;
Those
@var $name
Symbols are not very PHP friendly it seems.Thanks for the help, Tom.