{"action":"created","comment":{"url":"https://api.github.com/repos/librenms/librenms/pulls/comments/39347147","id":39347147,"diff_hunk":"@@ -0,0 +1,125 @@\n+<?php\n+/* Copyright (C) 2015 Sergiusz Paprzycki <serek@walcz.net>\n+ * \n+ * This widget is based on legacy frontpage module created by Paul Gear.\n+ *\n+ * This program is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU General Public License as published by\n+ * the Free Software Foundation, either version 3 of the License, or\n+ * (at your option) any later version.\n+ * \n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the\n+ * GNU General Public License for more details.\n+ * \n+ * You should have received a copy of the GNU General Public License\n+ * along with this program.  If not, see <http://www.gnu.org/licenses/>. */\n+\n+/**\n+ * Top devices by traffic\n+ * @author Sergiusz Paprzycki\n+ * @copyright 2015 Sergiusz Paprzycki <serek@walcz.net>\n+ * @license GPL\n+ * @package LibreNMS\n+ * @subpackage Widgets\n+ */\n+\n+if( defined('show_settings') || empty($widget_settings) ) {\n+    $common_output[] = '\n+<form class=\"form\" onsubmit=\"widget_settings(this); return false;\">\n+  <div class=\"form-group\">\n+    <div class=\"col-sm-6\">\n+      <label for=\"graph_type\" class=\"control-label\">Number of Devices: </label>\n+    </div>\n+    <div class=\"col-sm-4\">\n+      <input class=\"form-control\" name=\"device_count\" id=\"input_'.$unique_id.'\" placeholder=\"ie. 5\" value=\"'.$widget_settings['device_count'].'\">\n+    </div>\n+  </div>\n+  <div class=\"clearfix\"></div>\n+  <div class=\"form-group\">\n+    <div class=\"col-sm-6\">\n+      <label for=\"graph_type\" class=\"control-label\">Time interval (minutes): </label>\n+    </div>\n+    <div class=\"col-sm-4\">\n+      <input class=\"form-control\" name=\"time_interval\" id=\"input_'.$unique_id.'\" placeholder=\"ie. 15\" value=\"'.$widget_settings['time_interval'].'\">\n+    </div>\n+  </div>\n+  <div class=\"form-group\">\n+    <div class=\"col-sm-2\">\n+      <button type=\"submit\" class=\"btn btn-default\">Set</button>\n+    </div>\n+  </div>\n+</form>\n+    ';\n+}\n+else {\n+    $interval = $widget_settings['time_interval'];\n+    $interval_seconds = ($interval * 60);\n+    $device_count = $widget_settings['device_count'];\n+    $common_output[] = '\n+<h4>Top '.$device_count.' devices (last '.$interval.' minutes)</h4>\n+    ';\n+\n+    if (is_admin() || is_read()) {\n+        $query = '\n+            SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total\n+            FROM ports as p, devices as d\n+            WHERE d.device_id = p.device_id\n+            AND unix_timestamp() - p.poll_time < '.$interval_seconds.' ","path":"html/includes/common/top-devices.inc.php","position":69,"original_position":69,"commit_id":"028dc9c3ad0cc7bcb3cc7f6ab37d3ee12149eae3","original_commit_id":"028dc9c3ad0cc7bcb3cc7f6ab37d3ee12149eae3","user":{"login":"spaprzycki","id":10880890,"avatar_url":"https://avatars.githubusercontent.com/u/10880890?v=3","gravatar_id":"","url":"https://api.github.com/users/spaprzycki","html_url":"https://github.com/spaprzycki","followers_url":"https://api.github.com/users/spaprzycki/followers","following_url":"https://api.github.com/users/spaprzycki/following{/other_user}","gists_url":"https://api.github.com/users/spaprzycki/gists{/gist_id}","starred_url":"https://api.github.com/users/spaprzycki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spaprzycki/subscriptions","organizations_url":"https://api.github.com/users/spaprzycki/orgs","repos_url":"https://api.github.com/users/spaprzycki/repos","events_url":"https://api.github.com/users/spaprzycki/events{/privacy}","received_events_url":"https://api.github.com/users/spaprzycki/received_events","type":"User","site_admin":false},"body":"That's how I wanted to do it initially, but could not figure out a way (or find example) how to do it with different number of parameters depending on which query got selected. Non admin query has 3 parameters while admin query has only 2. The extra parameter comes first in non-admin query, so how do I 'tell' dbFetch to skip it on admin query? Do I need two dbFetch calls?\r\n\r\nI was looking around repo to find how other did that in the past, but failed to find one - all either have single parameter or use '.$var.' notation.","created_at":"2015-09-13T12:17:15Z","updated_at":"2015-09-13T12:17:15Z","html_url":"https://github.com/librenms/librenms/pull/1894#discussion_r39347147","pull_request_url":"https://api.github.com/repos/librenms/librenms/pulls/1894","_links":{"self":{"href":"https://api.github.com/repos/librenms/librenms/pulls/comments/39347147"},"html":{"href":"https://github.com/librenms/librenms/pull/1894#discussion_r39347147"},"pull_request":{"href":"https://api.github.com/repos/librenms/librenms/pulls/1894"}}},"pull_request":{"url":"https://api.github.com/repos/librenms/librenms/pulls/1894","id":44863274,"html_url":"https://github.com/librenms/librenms/pull/1894","diff_url":"https://github.com/librenms/librenms/pull/1894.diff","patch_url":"https://github.com/librenms/librenms/pull/1894.patch","issue_url":"https://api.github.com/repos/librenms/librenms/issues/1894","number":1894,"state":"open","locked":false,"title":"Top devices & top interfaces widgets","user":{"login":"spaprzycki","id":10880890,"avatar_url":"https://avatars.githubusercontent.com/u/10880890?v=3","gravatar_id":"","url":"https://api.github.com/users/spaprzycki","html_url":"https://github.com/spaprzycki","followers_url":"https://api.github.com/users/spaprzycki/followers","following_url":"https://api.github.com/users/spaprzycki/following{/other_user}","gists_url":"https://api.github.com/users/spaprzycki/gists{/gist_id}","starred_url":"https://api.github.com/users/spaprzycki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spaprzycki/subscriptions","organizations_url":"https://api.github.com/users/spaprzycki/orgs","repos_url":"https://api.github.com/users/spaprzycki/repos","events_url":"https://api.github.com/users/spaprzycki/events{/privacy}","received_events_url":"https://api.github.com/users/spaprzycki/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-12T23:15:42Z","updated_at":"2015-09-13T12:17:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5ea5493bbe76837b980fbaa2a429080146bc2609","assignee":{"login":"f0o","id":1656377,"avatar_url":"https://avatars.githubusercontent.com/u/1656377?v=3","gravatar_id":"","url":"https://api.github.com/users/f0o","html_url":"https://github.com/f0o","followers_url":"https://api.github.com/users/f0o/followers","following_url":"https://api.github.com/users/f0o/following{/other_user}","gists_url":"https://api.github.com/users/f0o/gists{/gist_id}","starred_url":"https://api.github.com/users/f0o/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/f0o/subscriptions","organizations_url":"https://api.github.com/users/f0o/orgs","repos_url":"https://api.github.com/users/f0o/repos","events_url":"https://api.github.com/users/f0o/events{/privacy}","received_events_url":"https://api.github.com/users/f0o/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/librenms/librenms/pulls/1894/commits","review_comments_url":"https://api.github.com/repos/librenms/librenms/pulls/1894/comments","review_comment_url":"https://api.github.com/repos/librenms/librenms/pulls/comments{/number}","comments_url":"https://api.github.com/repos/librenms/librenms/issues/1894/comments","statuses_url":"https://api.github.com/repos/librenms/librenms/statuses/028dc9c3ad0cc7bcb3cc7f6ab37d3ee12149eae3","head":{"label":"spaprzycki:issue-1892","ref":"issue-1892","sha":"028dc9c3ad0cc7bcb3cc7f6ab37d3ee12149eae3","user":{"login":"spaprzycki","id":10880890,"avatar_url":"https://avatars.githubusercontent.com/u/10880890?v=3","gravatar_id":"","url":"https://api.github.com/users/spaprzycki","html_url":"https://github.com/spaprzycki","followers_url":"https://api.github.com/users/spaprzycki/followers","following_url":"https://api.github.com/users/spaprzycki/following{/other_user}","gists_url":"https://api.github.com/users/spaprzycki/gists{/gist_id}","starred_url":"https://api.github.com/users/spaprzycki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spaprzycki/subscriptions","organizations_url":"https://api.github.com/users/spaprzycki/orgs","repos_url":"https://api.github.com/users/spaprzycki/repos","events_url":"https://api.github.com/users/spaprzycki/events{/privacy}","received_events_url":"https://api.github.com/users/spaprzycki/received_events","type":"User","site_admin":false},"repo":{"id":42018733,"name":"librenms","full_name":"spaprzycki/librenms","owner":{"login":"spaprzycki","id":10880890,"avatar_url":"https://avatars.githubusercontent.com/u/10880890?v=3","gravatar_id":"","url":"https://api.github.com/users/spaprzycki","html_url":"https://github.com/spaprzycki","followers_url":"https://api.github.com/users/spaprzycki/followers","following_url":"https://api.github.com/users/spaprzycki/following{/other_user}","gists_url":"https://api.github.com/users/spaprzycki/gists{/gist_id}","starred_url":"https://api.github.com/users/spaprzycki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spaprzycki/subscriptions","organizations_url":"https://api.github.com/users/spaprzycki/orgs","repos_url":"https://api.github.com/users/spaprzycki/repos","events_url":"https://api.github.com/users/spaprzycki/events{/privacy}","received_events_url":"https://api.github.com/users/spaprzycki/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/spaprzycki/librenms","description":"Community-based GPL-licensed network monitoring system","fork":true,"url":"https://api.github.com/repos/spaprzycki/librenms","forks_url":"https://api.github.com/repos/spaprzycki/librenms/forks","keys_url":"https://api.github.com/repos/spaprzycki/librenms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spaprzycki/librenms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spaprzycki/librenms/teams","hooks_url":"https://api.github.com/repos/spaprzycki/librenms/hooks","issue_events_url":"https://api.github.com/repos/spaprzycki/librenms/issues/events{/number}","events_url":"https://api.github.com/repos/spaprzycki/librenms/events","assignees_url":"https://api.github.com/repos/spaprzycki/librenms/assignees{/user}","branches_url":"https://api.github.com/repos/spaprzycki/librenms/branches{/branch}","tags_url":"https://api.github.com/repos/spaprzycki/librenms/tags","blobs_url":"https://api.github.com/repos/spaprzycki/librenms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spaprzycki/librenms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spaprzycki/librenms/git/refs{/sha}","trees_url":"https://api.github.com/repos/spaprzycki/librenms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spaprzycki/librenms/statuses/{sha}","languages_url":"https://api.github.com/repos/spaprzycki/librenms/languages","stargazers_url":"https://api.github.com/repos/spaprzycki/librenms/stargazers","contributors_url":"https://api.github.com/repos/spaprzycki/librenms/contributors","subscribers_url":"https://api.github.com/repos/spaprzycki/librenms/subscribers","subscription_url":"https://api.github.com/repos/spaprzycki/librenms/subscription","commits_url":"https://api.github.com/repos/spaprzycki/librenms/commits{/sha}","git_commits_url":"https://api.github.com/repos/spaprzycki/librenms/git/commits{/sha}","comments_url":"https://api.github.com/repos/spaprzycki/librenms/comments{/number}","issue_comment_url":"https://api.github.com/repos/spaprzycki/librenms/issues/comments{/number}","contents_url":"https://api.github.com/repos/spaprzycki/librenms/contents/{+path}","compare_url":"https://api.github.com/repos/spaprzycki/librenms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spaprzycki/librenms/merges","archive_url":"https://api.github.com/repos/spaprzycki/librenms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spaprzycki/librenms/downloads","issues_url":"https://api.github.com/repos/spaprzycki/librenms/issues{/number}","pulls_url":"https://api.github.com/repos/spaprzycki/librenms/pulls{/number}","milestones_url":"https://api.github.com/repos/spaprzycki/librenms/milestones{/number}","notifications_url":"https://api.github.com/repos/spaprzycki/librenms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spaprzycki/librenms/labels{/name}","releases_url":"https://api.github.com/repos/spaprzycki/librenms/releases{/id}","created_at":"2015-09-06T21:02:43Z","updated_at":"2015-09-06T21:03:22Z","pushed_at":"2015-09-12T23:14:43Z","git_url":"git://github.com/spaprzycki/librenms.git","ssh_url":"git@github.com:spaprzycki/librenms.git","clone_url":"https://github.com/spaprzycki/librenms.git","svn_url":"https://github.com/spaprzycki/librenms","homepage":"http://www.librenms.org/","size":59756,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"librenms:master","ref":"master","sha":"f4ac389a34dc56134244d4c12b91cbf99f6956a5","user":{"login":"librenms","id":5791783,"avatar_url":"https://avatars.githubusercontent.com/u/5791783?v=3","gravatar_id":"","url":"https://api.github.com/users/librenms","html_url":"https://github.com/librenms","followers_url":"https://api.github.com/users/librenms/followers","following_url":"https://api.github.com/users/librenms/following{/other_user}","gists_url":"https://api.github.com/users/librenms/gists{/gist_id}","starred_url":"https://api.github.com/users/librenms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/librenms/subscriptions","organizations_url":"https://api.github.com/users/librenms/orgs","repos_url":"https://api.github.com/users/librenms/repos","events_url":"https://api.github.com/users/librenms/events{/privacy}","received_events_url":"https://api.github.com/users/librenms/received_events","type":"Organization","site_admin":false},"repo":{"id":13914116,"name":"librenms","full_name":"librenms/librenms","owner":{"login":"librenms","id":5791783,"avatar_url":"https://avatars.githubusercontent.com/u/5791783?v=3","gravatar_id":"","url":"https://api.github.com/users/librenms","html_url":"https://github.com/librenms","followers_url":"https://api.github.com/users/librenms/followers","following_url":"https://api.github.com/users/librenms/following{/other_user}","gists_url":"https://api.github.com/users/librenms/gists{/gist_id}","starred_url":"https://api.github.com/users/librenms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/librenms/subscriptions","organizations_url":"https://api.github.com/users/librenms/orgs","repos_url":"https://api.github.com/users/librenms/repos","events_url":"https://api.github.com/users/librenms/events{/privacy}","received_events_url":"https://api.github.com/users/librenms/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/librenms/librenms","description":"Community-based GPL-licensed network monitoring system","fork":false,"url":"https://api.github.com/repos/librenms/librenms","forks_url":"https://api.github.com/repos/librenms/librenms/forks","keys_url":"https://api.github.com/repos/librenms/librenms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/librenms/librenms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/librenms/librenms/teams","hooks_url":"https://api.github.com/repos/librenms/librenms/hooks","issue_events_url":"https://api.github.com/repos/librenms/librenms/issues/events{/number}","events_url":"https://api.github.com/repos/librenms/librenms/events","assignees_url":"https://api.github.com/repos/librenms/librenms/assignees{/user}","branches_url":"https://api.github.com/repos/librenms/librenms/branches{/branch}","tags_url":"https://api.github.com/repos/librenms/librenms/tags","blobs_url":"https://api.github.com/repos/librenms/librenms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/librenms/librenms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/librenms/librenms/git/refs{/sha}","trees_url":"https://api.github.com/repos/librenms/librenms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/librenms/librenms/statuses/{sha}","languages_url":"https://api.github.com/repos/librenms/librenms/languages","stargazers_url":"https://api.github.com/repos/librenms/librenms/stargazers","contributors_url":"https://api.github.com/repos/librenms/librenms/contributors","subscribers_url":"https://api.github.com/repos/librenms/librenms/subscribers","subscription_url":"https://api.github.com/repos/librenms/librenms/subscription","commits_url":"https://api.github.com/repos/librenms/librenms/commits{/sha}","git_commits_url":"https://api.github.com/repos/librenms/librenms/git/commits{/sha}","comments_url":"https://api.github.com/repos/librenms/librenms/comments{/number}","issue_comment_url":"https://api.github.com/repos/librenms/librenms/issues/comments{/number}","contents_url":"https://api.github.com/repos/librenms/librenms/contents/{+path}","compare_url":"https://api.github.com/repos/librenms/librenms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/librenms/librenms/merges","archive_url":"https://api.github.com/repos/librenms/librenms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/librenms/librenms/downloads","issues_url":"https://api.github.com/repos/librenms/librenms/issues{/number}","pulls_url":"https://api.github.com/repos/librenms/librenms/pulls{/number}","milestones_url":"https://api.github.com/repos/librenms/librenms/milestones{/number}","notifications_url":"https://api.github.com/repos/librenms/librenms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/librenms/librenms/labels{/name}","releases_url":"https://api.github.com/repos/librenms/librenms/releases{/id}","created_at":"2013-10-28T01:37:13Z","updated_at":"2015-09-12T17:04:59Z","pushed_at":"2015-09-13T09:41:03Z","git_url":"git://github.com/librenms/librenms.git","ssh_url":"git@github.com:librenms/librenms.git","clone_url":"https://github.com/librenms/librenms.git","svn_url":"https://github.com/librenms/librenms","homepage":"http://www.librenms.org/","size":96140,"stargazers_count":232,"watchers_count":232,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":137,"mirror_url":null,"open_issues_count":158,"forks":137,"open_issues":158,"watchers":232,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/librenms/librenms/pulls/1894"},"html":{"href":"https://github.com/librenms/librenms/pull/1894"},"issue":{"href":"https://api.github.com/repos/librenms/librenms/issues/1894"},"comments":{"href":"https://api.github.com/repos/librenms/librenms/issues/1894/comments"},"review_comments":{"href":"https://api.github.com/repos/librenms/librenms/pulls/1894/comments"},"review_comment":{"href":"https://api.github.com/repos/librenms/librenms/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/librenms/librenms/pulls/1894/commits"},"statuses":{"href":"https://api.github.com/repos/librenms/librenms/statuses/028dc9c3ad0cc7bcb3cc7f6ab37d3ee12149eae3"}}}}