Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Tue Feb 19, 2019 8:01 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Autom8 adding host to all trees
PostPosted: Wed Dec 18, 2013 2:57 pm 
Offline

Joined: Mon Oct 21, 2013 10:16 am
Posts: 27
Unfortunately, the difficulty in figuring it out comes in that it does this only when my plugin, dpdiscover, adds the host.

My plugin essentially calls api_device_save (with id 0) to add newly discovered devices to Cacti, and relies on Autom8 to create the appropriate graphs and add the device to the tree structure built. Thing is, for every rule (as far as I can tell) enabled under "Tree Rules", Autom8 appears to be adding the host to the specified tree locations. IE, if I have tree rules:

1. Add to MSW - which adds the host under "Buildings" - "MSW", when the description begins with "msw"
2. Add to MSL - which adds the host under "Buildings" - "MSL", when the description begins with "msl"

If my plugin finds and adds msl-420-sw1, it ends up listed under both rules.

Autom8 debugging shows the following for every rule:

12/18/2013 01:35:27 PM - AUTOM8 TRACE: Poller[0] execute_device_create_tree Host[61], active rule: 8 name: Add to MSW type: 3
12/18/2013 01:35:27 PM - AUTOM8 TRACE: Poller[0] get_matching_hosts called: a:7:{s:2:"id";s:1:"8";s:4:"name";s:10:"Add to MSW";s:7:"tree_id";s:1:"3";s:12:"tree_item_id";s:2:"14";s:9:"leaf_type";s:1:"3";s:18:"host_grouping_type";s:1:"1";s:6:"rra_id";s:1:"0";} type: 3
12/18/2013 01:35:27 PM - AUTOM8 TRACE: Poller[0] build_matching_objects_filter called rule id: 8
12/18/2013 01:35:27 PM - AUTOM8 TRACE: Poller[0] build_rule_item_filter called: a:1:{i:0;a:8:{s:2:"id";s:2:"23";s:7:"rule_id";s:1:"8";s:9:"rule_type";s:1:"3";s:8:"sequence";s:1:"1";s:9:"operation";s:1:"0";s:5:"field";s:16:"host.description";s:8:"operator";s:1:"3";s:7:"pattern";s:3:"msw";}}, prefix:
12/18/2013 01:35:27 PM - AUTOM8 TRACE: Poller[0] build_rule_item_filter returns: host.description LIKE '%'
12/18/2013 01:35:27 PM - AUTOM8 TRACE: Poller[0] build_matching_objects_filter returns: host.description LIKE '%'
12/18/2013 01:35:27 PM - AUTOM8 TRACE: Poller[0] execute_device_create_tree Host[61], matching hosts: a:1:{i:0;a:6:{s:7:"host_id";s:2:"61";s:8:"hostname";s:13:"10.140.228.65";s:11:"description";s:12:"msl-240-gsw2";s:8:"disabled";s:0:"";s:6:"status";s:1:"0";s:18:"host_template_name";s:18:"USF Brocade Switch";}}
12/18/2013 01:35:27 PM - AUTOM8 TRACE: Poller[0] create_all_header_nodes called: Item 61 sql: SELECT * FROM plugin_autom8_tree_rule_items WHERE plugin_autom8_tree_rule_items.rule_id=8 ORDER BY sequence matches: 0 items
12/18/2013 01:35:27 PM - AUTOM8 TRACE: Poller[0] execute_device_create_tree Host[61], parent: 14
12/18/2013 01:35:27 PM - AUTOM8: Poller[0] create_device_node Host[61] Tree Item added - id: (426)
12/18/2013 01:35:27 PM - AUTOM8 TRACE: Poller[0] execute_device_create_tree Host[61], node: 426

As is indicated here, it almost appears as if the build_rule_item_filter isn't building the filter properly ... but I wouldn't know why.

As far as I can tell, if I add a device manually and tree item creation is on, it adds it appropriately. Ditto if I add it with tree item creation off, but then manually "Apply autom8 rules to devices".

So - any ideas? Any clues as to where I might look to resolve this behavior?

_________________
Eric Stewart
http://runningoffatthemouth.com/


Top
 Profile  
 
 Post subject: Re: Autom8 adding host to all trees
PostPosted: Wed Dec 18, 2013 3:58 pm 
Offline

Joined: Mon Oct 21, 2013 10:16 am
Posts: 27
I think I figured it out.

At one point "mysql_real_escape_string" is called. Unfortunately, I decided to be brave somewhere along the line and use mysqli as a database type instead of mysql. Since the function isn't compatible with the database type, it fails. That's my guess, anyway. Thing is, it shouldn't work properly *at all* if this is the case, so I'm not sure why I was thinking it was working when manually triggered.

In any event, if I change my database type back to "mysql", the bug doesn't occur.

Autom8 (and every other plugin, unfortunately) will need to be recoded to not use "mysql" specific functions, since:

Quote:
This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
mysqli_real_escape_string()
PDO::quote()


Either that, or perhaps there's a Cacti internal function?

_________________
Eric Stewart
http://runningoffatthemouth.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group