Change in API

Beta testing discussion area

Moderators: Moderators, Developers

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

Change in API

#1 Post by Rno » Mon Oct 29, 2018 4:51 am

Is it possible to make a general change in any evolution on API function ?
I mean when you decide to add a parameters, is it possible to:
1: add it at the end of the call
2: make it with a default value

So during migration at least current product are still able to work, and that let some time to adapt to the new definition ?

I'm using api_tree_item_save, and you decide to add the site_id in the middle of the call, an I don't think it's very good to act like that, since the CHANGELOG dosen't reflect that change:
1.2.0 Beta 1
-feature: Allow threads to be set a Data Collector level
-feature: Support Cacti 1.2's new data collection method
-feature: Escape strings more rubustly
-issue#50: make in Debian 7: undefined reference to `clock_gettime'
-issue#53: Variables are not being escaped properly when updating database
-issue#54: Spine should always report if ICMP fails
-issue#58: Error on poller.c: escaping string from snmp_sysLocation
-issue#63: Adjust Device Threads if a Device has fewer Data Sources
-issue: Align SQL_MODE's in spine with Cacti's database api
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.3, Map 0.4

Test
Cacti 1.2.1
Spine 1.2.1
thold 1.0.6
monitor 2.3.5
php 7.2.11
mariadb 5.5.56
Own plugin:
ExtendDB 1.1.2
LinkDiscovery 1.2.4
Map 1.2.5

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

Re: Change in API

#2 Post by netniV » Mon Oct 29, 2018 7:45 am

Now
function api_device_save($id, $host_template_id, $description, $hostname, $snmp_community, $snmp_version,
$snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disabled,
$availability_method, $ping_method, $ping_port, $ping_timeout, $ping_retries,
$notes, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_engine_id,
$max_oids = 5, $device_threads = 1, $poller_id = 1, $site_id = 1, $external_id = '', $location = '') {
Working backwards:
Location was added in commit f6510d680585e6b4461c1f2f3116bb436beb9bc0
External ID was added in commit 2e33bc95b29ec52032fa78f7bff024cd99239a6d
Site ID and Poller ID were changed from a ZERO default ot ONE in commit 8f304f744cdf67c3f08236f4f0e5d7178ab425bf
SNMP Engine ID was added in the middle in commit 76d75b0de33f790a27b33190c3785ecc939d57e5 (it's a required field)
Site ID and Poller ID were added in 247228c84e9790fce4415734559761bbb3eeed4a

These are all v1.2 changes as far as I can tell and all follow the practice you are describing with the exception of snmp_engine_id which unusually was added in the middle and does NOT have a default. That is irregular in terms of an API function but as with any API that could happen as it's a different version. If you are using this function from your own plugin, you can use the CACTI_VERSION constant to compare and see if that field would be required.

As the documentation is slowly being updated, that will also highlight potential API function call issues but we are not there yet.

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

Re: Change in API

#3 Post by Rno » Mon Oct 29, 2018 8:31 am

Hello,
Thanks,
But I'm talking about api_tree_item_save and can't find anything on when it change.
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.3, Map 0.4

Test
Cacti 1.2.1
Spine 1.2.1
thold 1.0.6
monitor 2.3.5
php 7.2.11
mariadb 5.5.56
Own plugin:
ExtendDB 1.1.2
LinkDiscovery 1.2.4
Map 1.2.5


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

Re: Change in API

#5 Post by netniV » Mon Oct 29, 2018 8:50 am

So that appears to be changed in commit 2c4b143c which was over a year ago in relation to:
https://github.com/cacti/cacti/issues/122

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

Re: Change in API

#6 Post by Rno » Mon Oct 29, 2018 9:09 am

Ok
was not on release 1.1.38
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.3, Map 0.4

Test
Cacti 1.2.1
Spine 1.2.1
thold 1.0.6
monitor 2.3.5
php 7.2.11
mariadb 5.5.56
Own plugin:
ExtendDB 1.1.2
LinkDiscovery 1.2.4
Map 1.2.5

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

Re: Change in API

#7 Post by netniV » Mon Oct 29, 2018 9:19 am

That's interesting, as I don't recall changing that in one of Howie's plugins that does tree manipulation. I'll have to have a look.

Post Reply