Page 1 of 1

Getting the Notes URL and Action URL

Posted: Wed Mar 23, 2011 12:29 am
by Box293
I am writing a component for internal use called the "Actions Tab".
Action Tab.png
When a user is looking at a specific service like disk space check, we want to provide them with a link that has our procedure on disk space checks.

I thought the Notes URL and the Action URL would be handy for these types of links. That way we put the specific link in the service based on the type of service it is.

Then it is a simple matter of pulling the Notes URL or the Action URL from the database. That way it is dynamic on the Actions tab based on the particular service I am looking at.

Make sense?
CCM Misc Settings.png
Do you have an example of the code I need to use to pull this information from the database? I've been playing with the function get_service_objects_xml_output() and it retrieves the information for all services however I don't know how to get the specific information for a) the service I am looking at and b)the Notes URL or Action URL.

My programming skills are stretched at this point. :o

Re: Getting the Notes URL and Action URL

Posted: Wed Mar 23, 2011 10:12 am
by tonyyarusso
I don't know the PHP functions for accessing or setting them (if any easily), but I can tell you that they are the notes_url and action_url fields in the tbl_service table of the nagiosql MySQL database.

Re: Getting the Notes URL and Action URL

Posted: Mon May 02, 2011 7:50 am
by Box293
Hi Tony,
I've been able to easily access the MySQL Database using the following php code:

Code: Select all

mysql_connect("localhost","root","nagiosxi")
I am just wondering if the MySQL username and password are stored in a variable? This way I don't need to hard code the username and password into the php code.

Cheers :)

Re: Getting the Notes URL and Action URL

Posted: Mon May 02, 2011 9:56 am
by mguthrie
You shouldn't need to mess with DB connections at all if you include the 'componenthelper.inc.php' script at the top of your file. Here's an outline of the important stuff that should save you a bunch of time. XI uses controlled access to the data on the backend, but here are the key items you should need to get your data.

Code: Select all

//necessary include file
 include_once(dirname(__FILE__).'/../componenthelper.inc.php');

//grab the GET variables and clean them
$host=grab_request_var("host","");
$service=grab_request_var("service","");

//get the unique service ID
$service_id=get_service_id($host,$service);

// get service details, create required arguments for backend 
	$args=array(
		"cmd" => "getservices",
		"service_id" => $service_id,
		);

//this will give you an XML object, loaded from the simplexml_load_string function
	$xml=get_backend_xml_data($args);	

//you should be able to access the variables you need with something like the following
 $notes = $xml->service->notes_url;
$action = $xml->service->action_url; 

//use  print_r($xml) to see a dumped output of the XML if there are other values that you need. 

Re: Getting the Notes URL and Action URL

Posted: Mon May 02, 2011 6:30 pm
by Box293
Cheers Mike, this is exactly what I am after.

Re: Getting the Notes URL and Action URL

Posted: Tue May 03, 2011 9:16 am
by rdedon
Very neat Troy! :-)