Cacti / plugin_mactrack

Mactrack Plugin for Cacti
GNU General Public License v2.0
12 stars 25 forks source link

Not working adding devices to cacti #232

Closed Cramin closed 1 month ago

Cramin commented 2 months ago

New instalation of cacti 1.2.27, added plugin mactrack, added device, snmp profile, site. Under device -> Import into device tracking -> and click Continue i have in logs:

2024-09-18 07:42:58 - CMDPHP ERRORS DETECTED - DISABLING PLUGIN 'mactrack'
2024-09-18 07:42:58 - CMDPHP PHP ERROR Backtrace:  (CactiShutdownHandler())
2024-09-18 07:42:58 - ERROR PHP ERROR in  Plugin 'mactrack':  Uncaught ArgumentCountError: Too few arguments to function  api_mactrack_device_save(), 27 passed in  /var/www/html/cacti/plugins/mactrack/mactrack_actions.php on line 303  and exactly 29 expected in  /var/www/html/cacti/plugins/mactrack/mactrack_actions.php:25 Stack  trace: #0  /var/www/html/cacti/plugins/mactrack/mactrack_actions.php(303):  api_mactrack_device_save() #1 /var/www/html/cacti/lib/plugins.php(282):  mactrack_device_action_execute() #2  /var/www/html/cacti/lib/plugins.php(161):  api_plugin_run_plugin_hook_function() #3  /var/www/html/cacti/host.php(357): api_plugin_hook_function() #4  /var/www/html/cacti/host.php(74): form_actions() #5 {main} thrown in  file: /var/www/html/cacti/plugins/mactrack/mactrack_actions.php on line:  25

To Reproduce Steps to reproduce the behavior:

  1. Go to Devices
  2. Click on first switch
  3. Finish configuration
  4. Click continue
  5. See error in logs

Expected behavior Working as expected.

Plugin mactrack:

OS Cacti Version: 1.2.27 Poller Type: Spine Spine version: SPINE 1.2.27 Copyright 2004-2023 by The Cacti Group Running on: Debian 12.7 Linux 6.8.12-1

Desktop:

TheWitness commented 2 months ago

Oh, crap. Did not see you assigned yourself @xmacan. My bad.

xmacan commented 2 months ago

@TheWitness never mind. I didn't start working on it yesterday :-)

Cramin commented 2 months ago

After applying commit

2024-09-19 11:06:44 - DBCALL ERROR: SQL Save Failed for Table  'mac_track_devices'.  SQL:'INSERT INTO mac_track_devices (`device_id`,  `host_id`, `site_id`, `hostname`, `device_name`, `notes`, `scan_type`,  `snmp_options`, `snmp_readstring`, `snmp_version`, `snmp_username`,  `snmp_password`, `snmp_auth_protocol`, `snmp_priv_passphrase`,  `snmp_priv_protocol`, `snmp_context`, `snmp_engine_id`, `snmp_port`,  `snmp_timeout`, `snmp_retries`, `max_oids`, `user_name`,  `user_password`, `ignorePorts`, `term_type`, `private_key_path`,  `disabled`, `scan_trunk_port`, `device_type_id`) VALUES (0, 2, 1,  '10.0.130.11', 'swzoz01.5548p.dell', '3CZ00Z1', 2, 1, 'public', '2', '',  '', '', '', '', '', '', 161, 500, 3, 10, '', '', '', 0, '', '', NULL,  0) ON DUPLICATE KEY UPDATE `host_id`=VALUES(`host_id`),  `site_id`=VALUES(`site_id`), `hostname`=VALUES(`hostname`),  `device_name`=VALUES(`device_name`), `notes`=VALUES(`notes`),  `scan_type`=VALUES(`scan_type`), `snmp_options`=VALUES(`snmp_options`),  `snmp_readstring`=VALUES(`snmp_readstring`),  `snmp_version`=VALUES(`snmp_version`),  `snmp_username`=VALUES(`snmp_username`),  `snmp_password`=VALUES(`snmp_password`),  `snmp_auth_protocol`=VALUES(`snmp_auth_protocol`),  `snmp_priv_passphrase`=VALUES(`snmp_priv_passphrase`),  `snmp_priv_protocol`=VALUES(`snmp_priv_protocol`),  `snmp_context`=VALUES(`snmp_context`),  `snmp_engine_id`=VALUES(`snmp_engine_id`),  `snmp_port`=VALUES(`snmp_port`), `snmp_timeout`=VALUES(`snmp_timeout`),  `snmp_retries`=VALUES(`snmp_retries`), `max_oids`=VALUES(`max_oids`),  `user_name`=VALUES(`user_name`),  `user_password`=VALUES(`user_password`),  `ignorePorts`=VALUES(`ignorePorts`), `term_type`=VALUES(`term_type`),  `private_key_path`=VALUES(`private_key_path`),  `disabled`=VALUES(`disabled`),  `scan_trunk_port`=VALUES(`scan_trunk_port`),  `device_type_id`=VALUES(`device_type_id`)'
2024-09-19 11:06:44 - CMDPHP SQL Backtrace:   (/host.php[74]:form_actions(),  /host.php[357]:api_plugin_hook_function(),  /lib/plugins.php[161]:api_plugin_run_plugin_hook_function(),  /lib/plugins.php[282]:mactrack_device_action_execute(),  /plugins/mactrack/mactrack_actions.php[304]:api_mactrack_device_save(),  /plugins/mactrack/mactrack_actions.php[68]:sql_save(),  /lib/database.php[1890]:_db_replace(),  /lib/database.php[1813]:db_execute(),  /lib/database.php[420]:db_execute_prepared())
2024-09-19 11:06:44 - CMDPHP ERROR: A DB Exec Failed!, Error: Column 'scan_trunk_port' cannot be null
2024-09-19 11:06:44 - CMDPHP PHP ERROR WARNING Backtrace:   (/host.php[74]:form_actions(),  /host.php[357]:api_plugin_hook_function(),  /lib/plugins.php[161]:api_plugin_run_plugin_hook_function(),  /lib/plugins.php[282]:mactrack_device_action_execute(),  /plugins/mactrack/mactrack_actions.php[333]:CactiErrorHandler())
2024-09-19 11:06:44 - ERROR PHP WARNING in  Plugin 'mactrack':  Undefined array key "device_type_id" in file:  /var/www/html/cacti/plugins/mactrack/mactrack_actions.php  on line: 333
2024-09-19 11:06:44 - CMDPHP PHP ERROR WARNING Backtrace:   (/host.php[74]:form_actions(),  /host.php[357]:api_plugin_hook_function(),  /lib/plugins.php[161]:api_plugin_run_plugin_hook_function(),  /lib/plugins.php[282]:mactrack_device_action_execute(),  /plugins/mactrack/mactrack_actions.php[332]:CactiErrorHandler())
2024-09-19 11:06:44 - ERROR PHP WARNING in  Plugin 'mactrack':  Undefined array key "scan_trunk_port" in file:  /var/www/html/cacti/plugins/mactrack/mactrack_actions.php  on line: 332
TheWitness commented 2 months ago

@xmacan, can you work through this to completion?

xmacan commented 2 months ago

@TheWitness ok, I will fix it

TheWitness commented 2 months ago

@xmacan, thanks. It looks like either the default is wrong in the table setup. I guess there are a few ways to go on it.

xmacan commented 2 months ago

@Cramin please show me result of sql query: describe mac_track_devices;

xmacan commented 2 months ago

@Cramin please run this SQL command: ALTER TABLE mac_track_devices MODIFY COLUMN scan_trunk_port text NULL default ''; use code from https://github.com/Cacti/plugin_mactrack/pull/233/files you need replace only mactrack_actions.php

Cramin commented 2 months ago

@Cramin please show me result of sql query: describe mac_track_devices;

Field,Type,Null,Key,Default,Extra
site_id,int(10) unsigned,NO,MUL,"0",""
device_id,int(10) unsigned,NO,PRI,,auto_increment
host_id,int(10) unsigned,NO,MUL,"0",""
device_name,varchar(100),YES,MUL,,""
device_type_id,int(10) unsigned,YES,MUL,"0",""
hostname,varchar(40),NO,"","",""
notes,text,YES,"",,""
disabled,char(2),YES,"",,""
ignorePorts,varchar(255),YES,"",,""
ips_total,int(10) unsigned,NO,"","0",""
vlans_total,int(10) unsigned,NO,"","0",""
ports_total,int(10) unsigned,NO,"","0",""
ports_active,int(10) unsigned,NO,"","0",""
ports_trunk,int(10) unsigned,NO,"","0",""
macs_active,int(10) unsigned,NO,"","0",""
scan_type,tinyint(11),NO,"",1,""
term_type,tinyint(11),NO,"",1,""
user_name,varchar(40),YES,"",,""
user_password,varchar(40),YES,"",,""
private_key_path,varchar(128),YES,"",,""
snmp_options,int(10) unsigned,NO,"","0",""
snmp_readstring,varchar(100),NO,"","",""
snmp_readstrings,varchar(255),YES,"",,""
snmp_version,varchar(100),NO,"","",""
snmp_port,int(10),NO,"",161,""
snmp_timeout,int(10) unsigned,NO,"",500,""
snmp_retries,tinyint(11) unsigned,NO,"",3,""
snmp_sysName,varchar(100),YES,"",,""
snmp_sysLocation,varchar(100),YES,"",,""
snmp_sysContact,varchar(100),YES,"",,""
snmp_sysObjectID,varchar(100),YES,MUL,,""
snmp_sysDescr,varchar(100),YES,MUL,,""
snmp_sysUptime,varchar(100),YES,"",,""
snmp_status,int(10) unsigned,NO,"","0",""
snmp_username,varchar(50),YES,"",,""
snmp_password,varchar(50),YES,"",,""
snmp_auth_protocol,char(5),YES,"",,""
snmp_priv_passphrase,varchar(200),YES,"",,""
snmp_priv_protocol,char(6),YES,"",,""
snmp_context,varchar(64),YES,"",,""
snmp_engine_id,varchar(64),YES,"",,""
max_oids,int(12) unsigned,YES,"",10,""
last_runmessage,varchar(100),YES,"",,""
last_rundate,timestamp,NO,"","0000-00-00 00:00:00",""
last_runduration,"decimal(10,5)",NO,"","0.00000",""
scan_trunk_port,text,NO,"",'',""

Now i can add device but in cacti.log i have errors.

2024-09-20 07:07:12 - CMDPHP PHP ERROR WARNING Backtrace:   (/host.php[74]:form_actions(),  /host.php[357]:api_plugin_hook_function(),  /lib/plugins.php[161]:api_plugin_run_plugin_hook_function(),  /lib/plugins.php[282]:mactrack_device_action_execute(),  /plugins/mactrack/mactrack_actions.php[333]:CactiErrorHandler())
2024-09-20 07:07:12 - ERROR PHP WARNING in  Plugin 'mactrack':  Undefined array key "device_type_id" in file:  /var/www/html/cacti/plugins/mactrack/mactrack_actions.php  on line: 333
2024-09-20 07:07:12 - CMDPHP PHP ERROR WARNING Backtrace:   (/host.php[74]:form_actions(),  /host.php[357]:api_plugin_hook_function(),  /lib/plugins.php[161]:api_plugin_run_plugin_hook_function(),  /lib/plugins.php[282]:mactrack_device_action_execute(),  /plugins/mactrack/mactrack_actions.php[332]:CactiErrorHandler())
2024-09-20 07:07:12 - ERROR PHP WARNING in  Plugin 'mactrack':  Undefined array key "scan_trunk_port" in file:  /var/www/html/cacti/plugins/mactrack/mactrack_actions.php  on line: 332

After mactrack poller:

2024-09-20 07:22:18 - MACTRACK ERROR: No device types have been found.
2024-09-20 07:22:18 - MACTRACK ERROR: No device types have been found.

And devices under Console -> Device Tracking -> Devices are Unknown.

xmacan commented 2 months ago

@Cramin It seems that you didn't use actual code. Please use code from actual develop branch.

Cramin commented 2 months ago

You got me, i aplied commit 367663b. Testing last changes. No errors for now.

xmacan commented 2 months ago

ok, thank you for reporting

Cramin commented 2 months ago

A lot of errors. Switch Dell 5548, SNMP v2c set. get_dell_dot1q_switch_ports

2024-09-20 09:08:34 - CMDPHP ERRORS DETECTED - DISABLING PLUGIN 'mactrack'
2024-09-20 09:08:34 - CMDPHP PHP ERROR Backtrace:  (CactiShutdownHandler())
2024-09-20 09:08:34 - ERROR PHP ERROR in  Plugin 'mactrack':  Uncaught TypeError: dechex(): Argument #1 ($num) must be of type int,  string given in  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php:256 Stack  trace: #0  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php(256):  dechex() #1  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php(207):  dell_mac_address_convert() #2  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php(57):  get_base_dell_dot1qFdb_ports() #3  /var/www/html/cacti/plugins/mactrack/mactrack_scanner.php(175):  get_dell_dot1q_switch_ports() #4 {main} thrown in file:  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php on line: 256

get_generic_dot1q_switch_ports

2024-09-20  09:14:35 - CMDPHP PHP ERROR WARNING Backtrace:   (/plugins/mactrack/mactrack_scanner.php[175]:get_generic_dot1q_switch_ports(),   /plugins/mactrack/lib/mactrack_functions.php[1200]:get_base_dot1qTpFdbEntry_ports(),  /plugins/mactrac
k/lib/mactrack_functions.php[1761]:CactiErrorHandler())
2024-09-20 09:14:35 - ERROR PHP WARNING in  Plugin 'mactrack':  Undefined array key ".150.248.188.18.133.190.176" in file:  /var/www/html/cacti/plugins/mactrack/lib/mactrack_functions.php  on  line: 1761
2024-09-20 09:14:35 - CMDPHP PHP ERROR WARNING Backtrace:   (/plugins/mactrack/mactrack_scanner.php[175]:get_generic_dot1q_switch_ports(),   /plugins/mactrack/lib/mactrack_functions.php[1200]:get_base_dot1qTpFdbEntry_ports(),  /plugins/mactrack/lib/mactrack_functions.php[1761]:CactiErrorHandler())
2024-09-20 09:14:35 - ERROR PHP WARNING in  Plugin 'mactrack':  Undefined array key ".150.224.204.248.117.250.234" in file:  /var/www/html/cacti/plugins/mactrack/lib/mactrack_functions.php  on  line: 1761

Screenshot 2024-09-20 at 09-17-10 Console Device Tracking Devices (Edit) Screenshot 2024-09-20 at 09-16-39 Console Device Tracking Device Types (Edit)

xmacan commented 2 months ago

Ok, I will take a look at it

xmacan commented 2 months ago

@Cramin - I need your help. I haven't any dell switch so I don't see data. Please edit file lib/mactrack_dell.php line 256: $mac_item = dechex($mac_item); to: cacti_log('dell_debug:' . $mac_item); $mac_item = dechex($mac_item); run gathering again and show log

xmacan commented 2 months ago

@Cramin For your second issue, please use lib/mactrack_function.php from https://github.com/Cacti/plugin_mactrack/pull/234

Cramin commented 2 months ago
2024-09-24 07:43:34 - CMDPHP ERRORS DETECTED - DISABLING PLUGIN 'mactrack'
2024-09-24 07:43:34 - CMDPHP PHP ERROR Backtrace:  (CactiShutdownHandler())
2024-09-24 07:43:34 - ERROR PHP ERROR in  Plugin 'mactrack':  Uncaught TypeError: dechex(): Argument #1 ($num) must be of type int,  string given in  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php:256 Stack  trace: #0  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php(256):  dechex() #1  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php(207):  dell_mac_address_convert() #2  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php(57):  get_base_dell_dot1qFdb_ports() #3  /var/www/html/cacti/plugins/mactrack/mactrack_scanner.php(175):  get_dell_dot1q_switch_ports() #4 {main} thrown in file:  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php on line: 256
2024-09-24 07:43:34 - CMDPHP dell_debug:
2024-09-24 07:43:33 - SYSTEM WARNING: Primary Admin account does not  have an email address!  Unable to send administrative Email.
2024-09-24 07:43:33 - CMDPHP ERRORS DETECTED - DISABLING PLUGIN 'mactrack'
2024-09-24 07:43:33 - CMDPHP PHP ERROR Backtrace:  (CactiShutdownHandler())
2024-09-24 07:43:33 - ERROR PHP ERROR in  Plugin 'mactrack':  Uncaught TypeError: dechex(): Argument #1 ($num) must be of type int,  string given in  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php:256 Stack  trace: #0  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php(256):  dechex() #1  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php(207):  dell_mac_address_convert() #2  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php(57):  get_base_dell_dot1qFdb_ports() #3  /var/www/html/cacti/plugins/mactrack/mactrack_scanner.php(175):  get_dell_dot1q_switch_ports() #4 {main} thrown in file:  /var/www/html/cacti/plugins/mactrack/lib/mactrack_dell.php on line: 256
2024-09-24 07:43:33 - CMDPHP dell_debug:

Only this is in log, dell debug log is empty.

xmacan commented 2 months ago

Logs tab -> search dell_debug
You should see at least one row starting "dell_debug"

Cramin commented 2 months ago

Yes, you can see above, dell_debug: as empty line.

xmacan commented 2 months ago

sorry, I overlooked it. Easy fix, please test https://github.com/Cacti/plugin_mactrack/pull/235

Cramin commented 1 month ago

I think this is solved.