debops / phpipam-scripts

A set of scripts designed to access phpIPAM database
GNU General Public License v3.0
31 stars 17 forks source link

ip address's state definition has been changed since phpipam v1.2 #1

Open ghost opened 8 years ago

ghost commented 8 years ago

Hello Maciej

I found you phpipam scripts very useful but since version 1.2 phpipam has been completely rewriten and your hardcoded statements of a state values don't fit it anymore

let me explain what have happened in python style in previous versions of phpipam there were a dictionary {active:1, reserver:2, offline:0, dhcp:3} now this dictionary has been trasformed to {active:2, reserver:3, offline:1, dhcp:4}

I would rewrite your code but I'am new to github so I don't know how to use it can you rewrite you script to match new version?

Thx, Nikolay

drybjed commented 8 years ago

@IDQDD Hello, and thanks for the heads up.

The phpIPAM script here is kind of crude, because it directly scrapes the MySQL database for relevant data. I would gladly change that to use the phpIPAM API, if/when I learn to use it programatically - I'm a sysadmin, not a programmer. :-)

Sure, I can update the scripts when I find some time. Do you know if the phpIPAM database has a version field which could be checked? That way the script could support both versions at the same time.

ghost commented 8 years ago

Maciej

IPAM API sounds good but do keep in mind they change their API as fast as MySQL structure :)

I did some greps and found out that the state values had been changed since version 1.1.5 this is an UPDATE-v1.15.sql (first line has an answer of your question about a version field)

/* Update version */ UPDATE settings set version = '1.15';

/* insert default values */ INSERT INTO ipTags (id, type, showtag, bgcolor, fgcolor, locked) VALUES (1, 'Offline', 1, '#f59c99', '#ffffff', 'Yes'), (2, 'Used', 0, '#a9c9a4', '#ffffff', 'Yes'), (3, 'Reserved', 1, '#9ac0cd', '#ffffff', 'Yes'), (4, 'DHCP', 1, '#c9c9c9', '#ffffff', 'Yes');

/* update ipaddresses */ UPDATE ipaddresses SET state = 1 WHERE state > 3; UPDATE ipaddresses SET state = 4 WHERE state = 3; UPDATE ipaddresses SET state = 3 WHERE state = 2; UPDATE ipaddresses SET state = 2 WHERE state = 1; UPDATE ipaddresses SET state = 1 WHERE state = 0;

p.s. I'm not a programmer either but seems we sysadmins have to become programmers to keep up the good job

drybjed commented 8 years ago

@IDQDD Indeed! Thanks for the research, I'll look into it when I have some time, perhaps on the weekend.

esebille commented 4 years ago

I have found a workaround to get IP addresses from the database.

If you use inet_ntoa(ip_addr) in the query it get the pointed decimal notation !

I'm trying to get the script to work, but we miss almost all hostnames in phpipam...