|
From: | Matthew Walker |
Subject: | Re: [Mibble-users] sorting OIDs |
Date: | Tue, 28 Jan 2014 17:30:25 -0500 |
User-agent: | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
Evening.. I ended up writing a MySQL function today to help with this.. This works for me since all the points found in MIBs (via mibble) I put into a DB. Here's how I use the function.. Just posting it here in case anyone else is looking to sort by OIDs Example usage ============================ SELECT oid_value from table_of_mibs order by OID_PAD(oid_value); OID_PAD FUNCTION ============================ DROP FUNCTION IF EXISTS OID_PAD; DELIMITER $$ CREATE FUNCTION OID_PAD(oid TEXT) RETURNS TEXT BEGIN DECLARE result TEXT; DECLARE segment VARCHAR(50); DECLARE oid_segments INT; DECLARE processed INT; #run this in mysql console before debugging is possible #create table log ( id int AUTO_INCREMENT, timestamp int default 0 , name varchar(64), value varchar(255), key(id)); SET oid_segments = (LENGTH(oid) - LENGTH(REPLACE(oid, '.', ''))) +1; SET processed = 0; SET result = ""; oid_loop: LOOP SET processed = processed + 1; SET segment = SUBSTRING_INDEX(SUBSTRING_INDEX(oid,'.',processed),'.',-1); IF LENGTH(segment) < 3 THEN SET segment = LPAD(segment,3,"0"); END IF; SET result = CONCAT(result,segment); #insert into log(timestamp,name,value) values(UNIX_TIMESTAMP(),"LOOP DEBUG",CONCAT(segment,':',processed)); IF processed = oid_segments THEN LEAVE oid_loop; END IF; END LOOP; RETURN result; END; $$ DELIMITER ; ======================= END FUNCTION -Matthew On 1/28/2014 12:16 PM, Per Cederberg
wrote:
|
[Prev in Thread] | Current Thread | [Next in Thread] |