DX Infrastructure Management

 View Only

Parse configuration file with Node.JS 

Mar 24, 2018 07:15 PM

Hi,

 

I created a Node.JS package capable to parse and read Nimsoft configuration File ( mainly for fun ). This can be a very good tools when you have to handle and manage many UIM Configuration files. Examples of use cases:

  • Manage cfg file in a Object format (Allow to store in almost any database like MongoDB, etc...).
  • Transform cfg file into Excel (many Node packages available)

 

Everything of this in Asynchrone by the way...

 

He can be mixed with a tool like NodeUIM easily ( Node.JS Asynchronous interface of Probe Utility ).

GitHub - UIM-Community/NodeUIM: CA UIM Probe Utility Asynchronous interface 

 

Usage example: 

 

(Your configuration file, script.cfg)

<setup>
     loglevel = 5
     probes = cdm,dirscan,processes
</setup>

 

Your JavaScript (code) file:

const nimCfgReader = require('nimcfgreader');

async function main() {
     const config = await (new nimCfgReader('./script.cfg')).read();
     
     const loglevel      = config.setup.loglevel || 5;
     const probes      = (config.setup.probes || '').split(',');
}
main().catch(console.error);

 

Parse buffer or string directly:

const config = nimCfgReader.parseConfigurationBuffer(`<setup>
loglevel = 5
</setup>`
);
console.log(config.setup.loglevel);

 

Performance: 

On my computer by running the package benchmark i get the following result:

PDS (File Buffer) Parsing x 41,891 ops/sec ±0.53% (90 runs sampled)

 

The configuration used for the test (sample from by perl probe static_enrichment) : 

<setup>
   loglevel = 5
   logsize = 1024
   debug = 0
   post_subject = alarm2
   pool_threads = 3
   timeout_interval = 5000
   heartbeat = 300
   qos = 30
</setup>
<enrichment-rules>
   exclusive_enrichment = no
   <100>
      match_alarm_field = udata.level
      match_alarm_regexp = 1
      <overwrite-rules>
         udata.enriched = 0#[udata.subsys]#[supp_key]
         udata.message = Hello world edited!
      </overwrite-rules>
   </100>
</enrichment-rules>

 

Parsing a file is a synchronous operation (tend to be a CPU Bound operation and starve the event-loop). So you have to be careful about use cases (example: using it when a HTTP Middleware is running aside is not a good idea).

 

Packages

GitHub - UIM-Community/nimCfgReader: PDS Configuration file parser 

 

That was a fun and good way for me to learn how to parse a Nimsoft configuration file... And the parsing performance is **** hot ( it can surely be heavily improved btw ).

 

Thanks for reading me ! 

 

Best Regards,

Thomas

Statistics
0 Favorited
0 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Apr 11, 2018 02:21 PM

Thomas, thank you for sharing this with the community!

Related Entries and Links

No Related Resource entered.