How and when automation and thold are called

Discussions on developing plugins for the Cacti Plugin Architecture

Moderators: Moderators, Developers

Post Reply
Author
Message
Rno
Cacti User
Posts: 361
Joined: Wed Dec 07, 2011 9:19 am

How and when automation and thold are called

#1 Post by Rno » Tue Dec 17, 2019 6:18 am

Hello,
I try to understand when the automation definition are called, and thold settings

I make a plugin who discover my network, and when I discover a device it make a call to api_device_save, after that I can see my device is saved, but many hook are not called:
thold template are not, only when I go to the device and hit save

The config for threshold is:
Auto Create Thresholds true
And I have a valid threshold template on the device

automation definition are not called, and for that I have to go the the device list, selection my device and make the choice: Apply automation rule

The config of automation is:
Enable Automatic Graph Creation true
Enable Automatic Tree Item Creation true


and for me that doesn't make sense!
1: why the thold are called only during a save ? (the only thing I saw is a call to api_plugin_hook_function('host_save') on the host.php during a save of a device
2: why automation are not called when a device is saved

any clue or hint on that is wrong ?

thanks in advance, and I'm using cacti 1.2.8
CentOS
Production
Cacti 0.8.8h
Spine 0.8.8h
PIA 3.1
Aggregate 0.75
Monitor 1.3
Settings 0.71
Weathermap 0.98
Thold 0.5
rrdclean 0.41

Own plugin: LinkDiscovery 0.45, Map 0.37

Test
Cacti 1.2.8
Spine 1.2.8
thold 1.0.6
monitor 2.3.5
syslog 2.4
php 7.2.11
mariadb 5.5.56
Own plugin:
ExtendDB 1.1.2
LinkDiscovery 1.2.6
Map 1.2.7

netniV
Cacti Guru User
Posts: 3080
Joined: Sun Aug 27, 2017 12:05 am

Re: How and when automation and thold are called

#2 Post by netniV » Tue Dec 17, 2019 9:27 am

thold hooks the following:

Code: Select all

includes/database.php:          api_plugin_register_hook('thold', 'rrd_graph_graph_options', 'thold_rrd_graph_graph_options', 'setup.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'graph_buttons', 'thold_graph_button', 'setup.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'data_source_action_array', 'thold_data_source_action_array', 'setup.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'data_source_action_prepare', 'thold_data_source_action_prepare', 'setup.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'data_source_action_execute', 'thold_data_source_action_execute', 'setup.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'graphs_action_array', 'thold_graphs_action_array', 'setup.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'graphs_action_prepare', 'thold_graphs_action_prepare', 'setup.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'graphs_action_execute', 'thold_graphs_action_execute', 'setup.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'config_insert', 'thold_config_insert', 'includes/settings.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'config_arrays', 'thold_config_arrays', 'includes/settings.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'config_form', 'thold_config_form', 'includes/settings.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'device_template_edit', 'thold_device_template_edit', 'setup.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'device_template_top', 'thold_device_template_top', 'setup.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'device_edit_pre_bottom', 'thold_device_edit_pre_bottom', 'setup.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'api_device_new', 'thold_api_device_new', 'setup.php', '1');
includes/database.php:          api_plugin_register_hook('thold', 'page_head', 'thold_page_head', 'setup.php');
includes/database.php:  api_plugin_register_hook('thold', 'host_edit_bottom', 'thold_host_edit_bottom', 'setup.php', '1');
setup.php:      api_plugin_register_hook($plugin, 'page_head', 'thold_page_head', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'top_header_tabs', 'thold_show_tab', 'includes/tab.php');
setup.php:      api_plugin_register_hook($plugin, 'top_graph_header_tabs', 'thold_show_tab', 'includes/tab.php');
setup.php:      api_plugin_register_hook($plugin, 'config_insert', 'thold_config_insert', 'includes/settings.php');
setup.php:      api_plugin_register_hook($plugin, 'config_arrays', 'thold_config_arrays', 'includes/settings.php');
setup.php:      api_plugin_register_hook($plugin, 'config_form', 'thold_config_form', 'includes/settings.php');
setup.php:      api_plugin_register_hook($plugin, 'config_settings', 'thold_config_settings', 'includes/settings.php');
setup.php:      api_plugin_register_hook($plugin, 'draw_navigation_text', 'thold_draw_navigation_text', 'includes/settings.php');
setup.php:      api_plugin_register_hook($plugin, 'poller_output', 'thold_poller_output', 'includes/polling.php');
setup.php:      api_plugin_register_hook($plugin, 'device_action_array', 'thold_device_action_array', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'device_action_execute', 'thold_device_action_execute', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'device_action_prepare', 'thold_device_action_prepare', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'api_device_save', 'thold_api_device_save', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'host_edit_bottom', 'thold_host_edit_bottom', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'device_threshold_autocreate', 'thold_device_autocreate', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'create_complete_graph_from_template', 'thold_create_graph_thold', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'poller_bottom', 'thold_poller_bottom', 'includes/polling.php');
setup.php:      api_plugin_register_hook($plugin, 'graph_buttons', 'thold_graph_button', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'graph_buttons_thumbnails', 'thold_graph_button', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'data_source_action_array', 'thold_data_source_action_array', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'data_source_action_prepare', 'thold_data_source_action_prepare', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'data_source_action_execute', 'thold_data_source_action_execute', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'data_source_remove', 'thold_data_source_remove', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'data_sources_table', 'thold_data_sources_table', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'graphs_action_array', 'thold_graphs_action_array', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'graphs_action_prepare', 'thold_graphs_action_prepare', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'graphs_action_execute', 'thold_graphs_action_execute', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'device_template_edit', 'thold_device_template_edit', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'device_template_top', 'thold_device_template_top', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'device_edit_pre_bottom', 'thold_device_edit_pre_bottom', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'api_device_new', 'thold_api_device_new', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'graphs_new_top_links', 'thold_graphs_new', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'update_host_status', 'thold_update_host_status', 'includes/polling.php');
setup.php:      api_plugin_register_hook($plugin, 'user_admin_setup_sql_save', 'thold_user_admin_setup_sql_save', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'rrd_graph_graph_options', 'thold_rrd_graph_graph_options', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'snmpagent_cache_install', 'thold_snmpagent_cache_install', 'setup.php');
setup.php:      api_plugin_register_hook($plugin, 'clog_regex_array', 'thold_clog_regex_array', 'setup.php');

Rno
Cacti User
Posts: 361
Joined: Wed Dec 07, 2011 9:19 am

Re: How and when automation and thold are called

#3 Post by Rno » Wed Dec 18, 2019 3:47 am

So if your right that mean something is not working as expected.

Since my plugin call api_device_save, and thold should be called after that.
My question is still open:
Why the threshold visible on my device, but not activated, is activated when a edit the device, click save again
After my plugin deiscover the device:
Interface - Status [int_status] Threshold Does Not Exist

and after I just click save on this device again:
Interface - Status [int_status] Threshold Exists
CentOS
Production
Cacti 0.8.8h
Spine 0.8.8h
PIA 3.1
Aggregate 0.75
Monitor 1.3
Settings 0.71
Weathermap 0.98
Thold 0.5
rrdclean 0.41

Own plugin: LinkDiscovery 0.45, Map 0.37

Test
Cacti 1.2.8
Spine 1.2.8
thold 1.0.6
monitor 2.3.5
syslog 2.4
php 7.2.11
mariadb 5.5.56
Own plugin:
ExtendDB 1.1.2
LinkDiscovery 1.2.6
Map 1.2.7

Rno
Cacti User
Posts: 361
Joined: Wed Dec 07, 2011 9:19 am

Re: How and when automation and thold are called

#4 Post by Rno » Wed Dec 18, 2019 8:32 am

I'm wondering if it's not the way I call api_device_save that confuse Cacti:

$new_hostid = api_device_save( '0', $snmp_array['host_template_id'], $hostrecord_array['description'],
$hostrecord_array['hostname'], $snmp_array['snmp_community'], $snmp_array['snmp_version'],
$snmp_array['snmp_username'], $snmp_array['snmp_password'], $snmp_array['snmp_port'],
$snmp_array['snmp_timeout'], $snmp_array['disable'], $snmp_array['availability_method'],
$snmp_array['ping_method'], $snmp_array['ping_port'], $snmp_array['ping_timeout'],
$snmp_array['ping_retries'], $snmp_array['notes'], $snmp_array['snmp_auth_protocol'],
$snmp_array['snmp_priv_passphrase'], $snmp_array['snmp_priv_protocol'], $snmp_array['snmp_context'],
$snmp_array['snmp_engine_id'], $snmp_array['max_oids'], $snmp_array['device_threads'], 1, 0 );

With the id as '0', and the return give me the real ID of the device. Maybe the id as to be set to '' (2 single quote)
And in the same time api_device_new dosen't exist in api_device.php, and I didn't find any doc on the API, even in the code

And By the way, dose the automation are called by a hook, or I have to call it every time ?
CentOS
Production
Cacti 0.8.8h
Spine 0.8.8h
PIA 3.1
Aggregate 0.75
Monitor 1.3
Settings 0.71
Weathermap 0.98
Thold 0.5
rrdclean 0.41

Own plugin: LinkDiscovery 0.45, Map 0.37

Test
Cacti 1.2.8
Spine 1.2.8
thold 1.0.6
monitor 2.3.5
syslog 2.4
php 7.2.11
mariadb 5.5.56
Own plugin:
ExtendDB 1.1.2
LinkDiscovery 1.2.6
Map 1.2.7

Rno
Cacti User
Posts: 361
Joined: Wed Dec 07, 2011 9:19 am

Re: How and when automation and thold are called

#5 Post by Rno » Thu Dec 19, 2019 6:20 am

Still not working. itry to look into the code of host.php to try to find out what is the difference when I create a host from the GUI or when I create using my plugin, but so far the only diff was a call to 'automation_update_device', but even adding that to my code dosen't make it behave like if it was done by cacti itself.

Soi here is 2 log ouputs, the first part (10:10:51 and 52) is the log when I create a device from my plugin using a call to either 'api_device_save' and then 'automation_update_device', the second part (10:39:31' is just the apply autom sync from the menu action.

Any clue where to look and whats is the difference on cacti when doing via a direct to an api or from the gui ?
2019/12/19 10:10:52 - AUTOM8 NOTE: [PID: 19232] create_device_node() Device[se-pama-2016] Tree Item - Already Exists
2019/12/19 10:10:52 - AUTOM8 TRACE [PID: 19232] automation_update_device() Create Tree for Device[se-pama-2016]
2019/12/19 10:10:52 - AUTOM8 TRACE [PID: 19232] automation_update_device() Found DQ[Cisco multi CPU] for Device[se-pama-2016]
2019/12/19 10:10:52 - AUTOM8 TRACE [PID: 19232] automation_update_device() Found DQ[SNMP - Interface Statistics] for Device[se-pama-2016]
2019/12/19 10:10:52 - AUTOM8 TRACE [PID: 19232] automation_update_device() Device[se-pama-2016]
2019/12/19 10:10:52 - DSTRACE Data Source values ""
2019/12/19 10:10:52 - DSTRACE Data Source keys ""
2019/12/19 10:10:52 - DSTRACE Data Source previous does not exist
2019/12/19 10:10:52 - DSTRACE Data Source Exists NOT Special Case "ifOperStatus"
2019/12/19 10:10:52 - DSTRACE Interface Speed Detected by ifHighSpeed: "1000000000"
2019/12/19 10:10:52 - DSTRACE Data Source values ""
2019/12/19 10:10:52 - DSTRACE Data Source keys ""
2019/12/19 10:10:52 - DSTRACE Data Source previous does not exist
2019/12/19 10:10:52 - DSTRACE Data Source Exists Special Case "ifHCInOctets,ifHCOutOctets"
2019/12/19 10:10:52 - AUTOM8 NOTE: [PID: 19232] create_device_node() Device[se-pama-2016] Tree Item - Added - Parent[11] Id[9832]
2019/12/19 10:10:51 - DSTRACE Running Re-Index for Device[se-pama-2016], DQ[Cisco multi CPU]
2019/12/19 10:10:51 - DSTRACE Field Name 'ifIP' found not suitable during Re-Index for Device[se-pama-2016], DQ[SNMP - Interface Statistics]
2019/12/19 10:10:51 - DSTRACE Field Name 'ifHwAddr' found not suitable. Non-unique and nonunique not specified during Re-Index for Device[se-pama-2016], DQ[SNMP - Interface Statistics]
2019/12/19 10:10:51 - DSTRACE Field Name 'ifHighSpeed' found not suitable during Re-Index for Device[se-pama-2016], DQ[SNMP - Interface Statistics]
2019/12/19 10:10:51 - DSTRACE Field Name 'ifSpeed' found not suitable during Re-Index for Device[se-pama-2016], DQ[SNMP - Interface Statistics]
2019/12/19 10:10:51 - DSTRACE Field Name 'ifType' found not suitable during Re-Index for Device[se-pama-2016], DQ[SNMP - Interface Statistics]
2019/12/19 10:10:51 - DSTRACE Field Name 'ifAlias' found not suitable during Re-Index for Device[se-pama-2016], DQ[SNMP - Interface Statistics]
2019/12/19 10:10:51 - DSTRACE Field Name 'ifName' found suitable during Re-Index for Device[se-pama-2016], DQ[SNMP - Interface Statistics]
2019/12/19 10:10:51 - DSTRACE Field Name 'ifDescr' found suitable during Re-Index for Device[se-pama-2016], DQ[SNMP - Interface Statistics]
2019/12/19 10:10:51 - DSTRACE Field Name 'ifAdminStatus' found not suitable during Re-Index for Device[se-pama-2016], DQ[SNMP - Interface Statistics]
2019/12/19 10:10:51 - DSTRACE Field Name 'ifOperStatus' found not suitable during Re-Index for Device[se-pama-2016], DQ[SNMP - Interface Statistics]
2019/12/19 10:10:51 - DSTRACE Field Name 'ifIndex' is an SNMP index and suitable Re-Index for Device[se-pama-2016], DQ[SNMP - Interface Statistics]
2019/12/19 10:10:51 - DSTRACE Available Sort Fields for Re-Index for Device[se-pama-2016], DQ[SNMP - Interface Statistics] are [ifName:ifDescr:ifHwAddr:ifIndex]
2019/12/19 10:10:51 - DSTRACE Running Re-Index for Device[se-pama-2016], DQ[SNMP - Interface Statistics]


2019/12/19 10:39:31 - AUTOM8 NOTE: [PID: 3773] create_device_node() Device[se-pama-2016] Tree Item - Already Exists
2019/12/19 10:39:31 - AUTOM8 TRACE [PID: 3773] automation_update_device() Create Tree for Device[se-pama-2016]
2019/12/19 10:39:31 - AUTOM8 NOTE: Graph Added - Device[se-pama-2016], Graph[ se-pama-2016 - CPU 1000 ], DS[se-pama-2016 - CPU 1000] Graphs[ se-pama-2016 - CPU 1000 ], Rule[CPU graph]
2019/12/19 10:39:31 - DSTRACE Data Source values ""
2019/12/19 10:39:31 - DSTRACE Data Source keys ""
2019/12/19 10:39:31 - DSTRACE Data Source previous does not exist
2019/12/19 10:39:31 - DSTRACE Data Source Exists NOT Special Case "cCpu1Min,cCpu5Min,cCpu5Sec"
2019/12/19 10:39:30 - AUTOM8 TRACE [PID: 3773] automation_update_device() Found DQ[Cisco multi CPU] for Device[se-pama-2016]
2019/12/19 10:39:30 - AUTOM8 TRACE [PID: 3773] automation_update_device() Found DQ[SNMP - Interface Statistics] for Device[se-pama-2016]
2019/12/19 10:39:30 - AUTOM8 TRACE [PID: 3773] automation_update_device() Device[se-pama-2016]
2019/12/19 10:39:30 - AUTOM8 TRACE form_actions, items: a:1:{i:0;s:4:"7497";}
2019/12/19 10:39:30 - AUTOM8 TRACE form_actions called, action: 6
CentOS
Production
Cacti 0.8.8h
Spine 0.8.8h
PIA 3.1
Aggregate 0.75
Monitor 1.3
Settings 0.71
Weathermap 0.98
Thold 0.5
rrdclean 0.41

Own plugin: LinkDiscovery 0.45, Map 0.37

Test
Cacti 1.2.8
Spine 1.2.8
thold 1.0.6
monitor 2.3.5
syslog 2.4
php 7.2.11
mariadb 5.5.56
Own plugin:
ExtendDB 1.1.2
LinkDiscovery 1.2.6
Map 1.2.7

Rno
Cacti User
Posts: 361
Joined: Wed Dec 07, 2011 9:19 am

Re: How and when automation and thold are called

#6 Post by Rno » Thu Jan 09, 2020 1:22 am

Still no information on why automation is not called !!

Sucks!!
CentOS
Production
Cacti 0.8.8h
Spine 0.8.8h
PIA 3.1
Aggregate 0.75
Monitor 1.3
Settings 0.71
Weathermap 0.98
Thold 0.5
rrdclean 0.41

Own plugin: LinkDiscovery 0.45, Map 0.37

Test
Cacti 1.2.8
Spine 1.2.8
thold 1.0.6
monitor 2.3.5
syslog 2.4
php 7.2.11
mariadb 5.5.56
Own plugin:
ExtendDB 1.1.2
LinkDiscovery 1.2.6
Map 1.2.7

netniV
Cacti Guru User
Posts: 3080
Joined: Sun Aug 27, 2017 12:05 am

Re: How and when automation and thold are called

#7 Post by netniV » Sat Jan 11, 2020 6:46 pm

Apologies, there simply hasn't been enough time between Christmas, work changing the way they are doing things, etc.

Post Reply