Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adding custom quick links to device navigation #10403

Merged
merged 5 commits into from Aug 20, 2019

Conversation

@jasoncheng7115
Copy link
Contributor

commented Jul 2, 2019

In the device page menu, I add a link to open-audit to show the device asset details.

To enable this feature, you need to add a setting value in config.php, such as:
$config['openaudit_web_device'] = "http://atssrv.com/open-audit/index.php/devices/";

The display results are shown as follows:

2019-07-02 13_25_46-vm-014 - LibreNMS
2019-07-02 13_26_57-Open-AudIT

DO NOT DELETE THIS TEXT

Please note

Please read this information carefully. You can run ./scripts/pre-commit.php to check your code before submitting.

Testers

If you would like to test this pull request then please run: ./scripts/github-apply <pr_id>, i.e ./scripts/github-apply 5926
After you are done testing, you can remove the changes with ./scripts/github-remove. If there are schema changes, you can ask on discord how to revert.

@laf

This comment has been minimized.

Copy link
Member

commented Jul 2, 2019

It would be better to standardise adding in additional http links, especially when it's most likely going to be pretty much the same for each link. Also sysDescr might not be what people want as the reference name.

Maybe something like:

foreach (Config::get('html.device.links', []) as $links) {
    $html_link = view(['template' => $links['url'], $device)->__toString();
    echo '<li><a href=" . $html_link . " onclick="http_fallback(this); return false;" target="_blank" rel="noopener"><i class="fa fa-globe fa-lg icon-theme"  aria-hidden="true"></i> ' . $links['title'] . '</a></li>';
}

You can then do this in config.php:

$config['html']['device']['links'] = ['url' => 'https://url.to.something.com/devices/{{ $device[\'hostname\'] }}', 'title' => 'Open-AudIT'];

Docs will also need updating to reflect what you can do here.

Totally untested btw.

@jasoncheng7115

This comment has been minimized.

Copy link
Contributor Author

commented Jul 2, 2019

It would be better to standardise adding in additional http links, especially when it's most likely going to be pretty much the same for each link. Also sysDescr might not be what people want as the reference name.

Maybe something like:

foreach (Config::get('html.device.links', []) as $links) {
    $html_link = view(['template' => $links['url'], $device)->__toString();
    echo '<li><a href=" . $html_link . " onclick="http_fallback(this); return false;" target="_blank" rel="noopener"><i class="fa fa-globe fa-lg icon-theme"  aria-hidden="true"></i> ' . $links['title'] . '</a></li>';
}

You can then do this in config.php:

$config['html']['device']['links'] = ['url' => 'https://url.to.something.com/devices/{{ $device[\'hostname\'] }}', 'title' => 'Open-AudIT'];

Docs will also need updating to reflect what you can do here.

Totally untested btw.

Oh, thanks! This is a great idea. I'll test it and change the code.

@jasoncheng7115

This comment has been minimized.

Copy link
Contributor Author

commented Jul 2, 2019

Hi @laf,
I have modified your sample code and used it for testing, rewriting it as follows:

device.inc.php
foreach (Config::get('html.device.links') as $links) {
$html_link = view(['template' => $links['url']], $device)->__toString();
echo '<li><a href="'.$html_link.'" onclick="http_fallback(this); return false;" target="_blank" rel="noopener"><i class="fa fa-globe fa-lg icon-theme" aria-hidden="true"></i> '.$links['title'].'</a></li>';
}

config.php
$config['html']['device']['links'] = [['url' => 'http://atssrv/open-audit/index/devices/{{ $device[\'hostname\'] }}', 'title' => 'Open-AudIT-TEST']];

Execution is fine,
but the key $device['hostname'] is not replaced with the hostname. Is there something missing? Thank you for your help.

@bestlong

This comment has been minimized.

Copy link
Contributor

commented Jul 4, 2019

@jasoncheng7115

foreach (Config::get('html.device.links') as $links) {
	$html_link = view(['template' => $links['url']], ['device' => $device])->__toString();
	echo '<li><a href="'.$html_link.'" onclick="http_fallback(this); return false;" target="_blank" rel="noopener"><i class="fa fa-globe fa-lg icon-theme" aria-hidden="true"></i> '.$links['title'].'</a></li>';
}
@jasoncheng7115

This comment has been minimized.

Copy link
Contributor Author

commented Jul 4, 2019

Thanks @bestlong support, it's test ok.

Thanks @laf, The code has been changed and commit in this pr, and the config.php example is:

$config['html']['device']['links'] = [['url' => 'http://atsserver.com/open-audit/index.php/devices/{{ $device[\'sysName\'] }}', 'title' => 'Open-AudIT']];

@laf

This comment has been minimized.

Copy link
Member

commented Jul 9, 2019

Thanks @jasoncheng7115 and @bestlong.

@jasoncheng7115 If you can update https://github.com/jasoncheng7115/librenms/blob/patch-13/doc/Extensions/Customizing-the-Web-UI.md and add some docs and config examples around this then we should be good to go.

@jasoncheng7115

This comment has been minimized.

Copy link
Contributor Author

commented Jul 9, 2019

Thanks @jasoncheng7115 and @bestlong.

@jasoncheng7115 If you can update https://github.com/jasoncheng7115/librenms/blob/patch-13/doc/Extensions/Customizing-the-Web-UI.md and add some docs and config examples around this then we should be good to go.

Ok, let's see, let's look at how do i create it.
Thanks @laf .

@jasoncheng7115

This comment has been minimized.

Copy link
Contributor Author

commented Jul 10, 2019

@laf I have updated Customizing-the-Web-UI.md, thanks.

laf added 2 commits Aug 20, 2019
@murrant
Copy link
Member

left a comment

LGTM, title needs updating

@murrant murrant changed the title Add Open-Audit link display device asset details Allow adding custom device links Aug 20, 2019

@murrant murrant added Feature and removed User-Pending labels Aug 20, 2019

@laf laf changed the title Allow adding custom device links Allow adding custom quick links to device navigation Aug 20, 2019

@laf laf merged commit 49310dc into librenms:master Aug 20, 2019

6 checks passed

Inspection Summary
Details
Node: analysis
Details
Travis CI - Pull Request Build Passed
Details
WIP Ready for review
Details
codeclimate All good!
Details
license/cla Contributor License Agreement is signed.
Details
@murrant

This comment has been minimized.

Copy link
Member

commented Sep 3, 2019

This pull request has been mentioned on LibreNMS Community. There might be relevant details there:

https://community.librenms.org/t/v1-55-release-changelog-august-2019/9428/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.