how to get the ID of graphs
Moderators: Developers, Moderators
how to get the ID of graphs
Hello to all
i need to get a list of ID in a PHP array or CSV
later , via the NMID SOAP WebService i plan/think to show all the graphs for a given user
so for example if the user that browsing my mini-portal is John then i need to get all the graph`s IDs that
this user is allowed to view
what im looking is just the SQL query to get all the IDs that a user is allowed to view
thanks
i need to get a list of ID in a PHP array or CSV
later , via the NMID SOAP WebService i plan/think to show all the graphs for a given user
so for example if the user that browsing my mini-portal is John then i need to get all the graph`s IDs that
this user is allowed to view
what im looking is just the SQL query to get all the IDs that a user is allowed to view
thanks
- phalek
- Developer
- Posts: 2838
- Joined: Thu Jan 31, 2008 6:39 am
- Location: Kressbronn, Germany
- Contact:
Re: how to get the ID of graphs
Do you just want to get the graph ids or also the title for the graph ?
I can add a function for this to the nmidWebService plugin if you like.
I can add a function for this to the nmidWebService plugin if you like.
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Re: how to get the ID of graphs
thanks for your quick reply
right now i was thinking that having the graph IDs and hostnames would be great
but as much as we can have would be greatest
look at this as the mediation for cacti to be used with other web services
like creating a mini-portal for users to have an idea of capacity/bandwidth but without going in cacti
or maybe integrate cacti with other mainstream application like wordpress , joomla
and since on WP there can be too many users we can for example show the graphs that belongs to that user
The nmidWebService can use an admin ( user that have all access on all graphs ) but will be the WP/joomla that will require
the list of graphs for a given user to nmidWebService
looking forward
right now i was thinking that having the graph IDs and hostnames would be great
but as much as we can have would be greatest
look at this as the mediation for cacti to be used with other web services
like creating a mini-portal for users to have an idea of capacity/bandwidth but without going in cacti
or maybe integrate cacti with other mainstream application like wordpress , joomla
and since on WP there can be too many users we can for example show the graphs that belongs to that user
The nmidWebService can use an admin ( user that have all access on all graphs ) but will be the WP/joomla that will require
the list of graphs for a given user to nmidWebService
looking forward
- phalek
- Developer
- Posts: 2838
- Joined: Thu Jan 31, 2008 6:39 am
- Location: Kressbronn, Germany
- Contact:
Re: how to get the ID of graphs
Yes, the whole integration part is the reason why I created the nmidWebService plugin.
I'm using it for my Android app as well in order to not have to fiddle around with html source code or database internals.
For your Info, the "allowed graphs" part contains several sql requests, here's part of the code which manages this. ( out of graph_functions.php of the nmidWebService plugin ).
I'm using it for my Android app as well in order to not have to fiddle around with html source code or database internals.
For your Info, the "allowed graphs" part contains several sql requests, here's part of the code which manages this. ( out of graph_functions.php of the nmidWebService plugin ).
Code: Select all
$i_db_userId = < database id of the user >;
$current_user = array();
$current_user["policy_graphs"] = getDBValue('policy_graphs',"select policy_graphs from user_auth where id=" . $i_db_userId);
$current_user["policy_hosts"] = getDBValue('policy_hosts',"select policy_hosts from user_auth where id=" . $i_db_userId);
$current_user["policy_graph_templates"] = getDBValue('policy_graph_templates',"select policy_graph_templates from user_auth where id=" . $i_db_userId);
/* get policy information for the sql where clause */
$sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
"SELECT
graph_templates_graph.local_graph_id as lgid
FROM
(graph_templates_graph,graph_local)
LEFT JOIN
host ON (host.id=graph_local.host_id)
LEFT JOIN
graph_templates ON (graph_templates.id=graph_local.graph_template_id)
LEFT JOIN
user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $i_db_userId . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $i_db_userId . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $i_db_userId . "))
WHERE
graph_templates_graph.local_graph_id=graph_local.id
" . (empty($sql_where) ? "" : "and $sql_where") . "
GROUP BY graph_templates_graph.local_graph_id"
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Re: how to get the ID of graphs
so all we need to do is to add a function on the list of exported WSDL services and also the same function that will execute that sql , accepting the ID of the user as a param ?
- phalek
- Developer
- Posts: 2838
- Joined: Thu Jan 31, 2008 6:39 am
- Location: Kressbronn, Germany
- Contact:
Re: how to get the ID of graphs
yes, basically that's true.
But, the question is how to secure this function so not everyone knowing the webservices password is able to retrieve this data, after all there may be some ppl who have multiple customers on there and they don't want them to see the graph/names of the other customers.
But, the question is how to secure this function so not everyone knowing the webservices password is able to retrieve this data, after all there may be some ppl who have multiple customers on there and they don't want them to see the graph/names of the other customers.
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Re: how to get the ID of graphs
not a big prob in this case since we are "all-trusted" people and the data isnt so sensitive
not to forget that the customers are common people , not geek
also i was thinking that having a user id search by name ( select id from users where username=$param)
would be nicer
thanks again
not to forget that the customers are common people , not geek
also i was thinking that having a user id search by name ( select id from users where username=$param)
would be nicer
thanks again
- phalek
- Developer
- Posts: 2838
- Joined: Thu Jan 31, 2008 6:39 am
- Location: Kressbronn, Germany
- Contact:
Re: how to get the ID of graphs
Ok, here's what you need:
Somewhere in graph_functions.php add the following code:
in webservice.php add the following lines to the list at the end of the file right before the ->handle() lines:
and
Then you can use a client to get the data:
you will get a list like this one ( lgid;title ):
Somewhere in graph_functions.php add the following code:
Code: Select all
/**
* Get a complete list of graphs allowed for the selected user
* @param string $s_username
* @return string
*/
function get_allowed_graphs_for_user($s_username) {
$s_username = getTextEscaped( $s_username );
$i_db_userId = getDBValue('id','select id from user_auth where upper(USERNAME) = "'.strtoupper($s_username).'"');
$current_user = array();
$current_user["policy_graphs"] = getDBValue('policy_graphs',"select policy_graphs from user_auth where id=" . $i_db_userId);
$current_user["policy_hosts"] = getDBValue('policy_hosts',"select policy_hosts from user_auth where id=" . $i_db_userId);
$current_user["policy_graph_templates"] = getDBValue('policy_graph_templates',"select policy_graph_templates from user_auth where id=" . $i_db_userId);
/* get policy information for the sql where clause */
$sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
$sql = "select
graph_templates_graph.local_graph_id as lgid,
graph_templates_graph.title_cache as title_cache
from (graph_templates_graph,graph_local)
left join host on (host.id=graph_local.host_id)
left join graph_templates on (graph_templates.id=graph_local.graph_template_id)
left join user_auth_perms on ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $i_db_userId . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $i_db_userId . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $i_db_userId . "))
where graph_templates_graph.local_graph_id=graph_local.id
" . (empty($sql_where) ? "" : "and $sql_where") . "
group by graph_templates_graph.local_graph_id";
$o_result = mysql_query( $sql );
$return_string = '';
while ( $a_row = mysql_fetch_assoc( $o_result ) ) {
$return_string .= $a_row['lgid'].';'.$a_row['title_cache']."\n";
}
mysql_free_result( $o_result );
if ( strlen($return_string) > 0) {
return $return_string;
}else{
return 'No Graphs';
}
}
Code: Select all
$autodiscover->addFunction('get_allowed_graphs_for_user');
Code: Select all
$server->addFunction('get_allowed_graphs_for_user');
Code: Select all
<?php
$webservice_url = 'http://localhost/cacti/plugins/nmidWebService/webservice.php?wsdl';
$cacti_userid = "admin";
$client = new SoapClient($webservice_url);
print $client->get_allowed_graphs_for_user( $cacti_userid );
?>
Code: Select all
1456;localhost - Cacti User Login Statistic
1457;localhost - Cacti User Session Statistic
1458;localhost - Cacti User Statistic
1644;localhost - InnoDB Active/Locked Transactions
1645;localhost - InnoDB Adaptive Hash Index
1646;localhost - InnoDB Buffer Pool Activity
1647;localhost - InnoDB Buffer Pool
1648;localhost - InnoDB Checkpoint Age
1649;localhost - InnoDB Current Lock Waits
1650;localhost - InnoDB I/O
1651;localhost - InnoDB I/O Pending
1652;localhost - InnoDB Insert Buffer
1653;localhost - InnoDB Insert Buffer Usage
1654;localhost - InnoDB Internal Hash Memory Usage
1655;localhost - InnoDB Lock Structures
1656;localhost - InnoDB Log
1657;localhost - InnoDB Memory Allocation
1658;localhost - InnoDB Row Lock Time
1659;localhost - InnoDB Row Lock Waits
1660;localhost - InnoDB Row Operations
1661;localhost - InnoDB Semaphore Wait Time
1662;localhost - InnoDB Semaphore Waits
1663;localhost - InnoDB Semaphores
1664;localhost - InnoDB Tables In Use
1665;localhost - InnoDB Transactions
1666;localhost - MyISAM Indexes
1667;localhost - MyISAM Key Cache
1668;localhost - MySQL Binary/Relay Logs
1669;localhost - MySQL Command Counters
1670;localhost - MySQL Connections
1671;localhost - MySQL Files and Tables
1672;localhost - MySQL Handlers
1673;localhost - MySQL Network Traffic
1674;localhost - MySQL Processlist
1675;localhost - MySQL Query Cache
1676;localhost - MySQL Query Cache Memory
1677;localhost - MySQL Query Response Time (Microseconds)
1678;localhost - MySQL Query Time Histogram (Count)
1679;localhost - MySQL Replication
1680;localhost - MySQL Select Types
1681;localhost - MySQL Sorts
1682;localhost - MySQL Table Locks
1683;localhost - MySQL Temporary Objects
1684;localhost - MySQL Threads
1685;localhost - MySQL Transaction Handler
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Re: how to get the ID of graphs
thanx buddy , but for a strange reason adding the function to the graph_functions.php doesnt do the trick
on the error logs of apache i see this
but adding the same function on the webservice.php its OK
thanks again
on the error logs of apache i see this
Code: Select all
[Mon Apr 30 08:02:11 2012] [error] [client 46.183.11.11] PHP Fatal error: Uncaught SoapFault exception: [HTTP] Internal Server Error in /var/www/html/cacti-soap.php:8\nStack trace:\n#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://46.183.1...', 'http://46.183.1...', 1, 0)\n#1 /var/www/html/cacti-soap.php(8): SoapClient->__call('authUser', Array)\n#2 /var/www/html/cacti-soap.php(8): SoapClient->authUser('admin', '$jf.ijhsd/455', 'cctitv')\n#3 {main}\n thrown in /var/www/html/cacti-soap.php on line 8
but adding the same function on the webservice.php its OK
thanks again
- phalek
- Developer
- Posts: 2838
- Joined: Thu Jan 31, 2008 6:39 am
- Location: Kressbronn, Germany
- Contact:
Re: how to get the ID of graphs
But you are using v2.xx oft the nmidWebService plugin, right ?
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Re: how to get the ID of graphs
yes , on the cacti`s plugin interface i see
NmidWebService 2.08
as i said , adding the function on webservice.php it works OK , so not a big prob
regards
NmidWebService 2.08
as i said , adding the function on webservice.php it works OK , so not a big prob
regards
- phalek
- Developer
- Posts: 2838
- Joined: Thu Jan 31, 2008 6:39 am
- Location: Kressbronn, Germany
- Contact:
Re: how to get the ID of graphs
Ok and please read your PM
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Re: how to get the ID of graphs
i wish to but ....
Code: Select all
You are not authorised to read private messages.
- phalek
- Developer
- Posts: 2838
- Joined: Thu Jan 31, 2008 6:39 am
- Location: Kressbronn, Germany
- Contact:
Re: how to get the ID of graphs
haha,
then: Edit your post and remove the error messages ... to much unnecessary data in there. And most of us here are all geeks
then: Edit your post and remove the error messages ... to much unnecessary data in there. And most of us here are all geeks
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Re: how to get the ID of graphs
phalek wrote:haha,
then: Edit your post and remove the error messages ... to much unnecessary data in there. And most of us here are all geeks
thats not my real IP , just random data and user/passes
im too paranoid myself
Who is online
Users browsing this forum: No registered users and 3 guests