Welcome to OCS Inventory NG community support, where you can ask questions and receive answers from other members of the community.

Please ask questions only in English or French.

Release 2.12.3 available

The official documentation can be found on https://wiki.ocsinventory-ng.org. Read it before asking your question.

push custom software XML from agent plugin

Hello,

Trying to move from fusioninventory (FI) to OCS. I used FI to add custom softwares to the agent report. Trying to do the same with OCS.

So I wrote a plugin, starting from the Example.pm plugin. Here's the inventory_handler function :

sub freepbx_inventory_handler {        #Use this hook to add or modify entries in the inventory XML
    my $self = shift;
    my $logger = $self->{logger};

    $logger->debug("Yeah you are in freepbx_inventory_handler :)");
    my $json = JSON->new->utf8->boolean_values(0, 1);  # false → 0, true → 1
    # JSON string
    my $json_text = `/usr/sbin/fwconsole ma list --format json | tail -n1`;

    # Decode JSON to perl object
    my $decoded = $json->decode($json_text);

    my @modules;
    foreach my $entry (@{$decoded->{data}}) {
        push @modules, {
            NAME     => $entry->[0],
            VERSION  => $entry->[1],
            PUBLISHER => $entry->[4],
            FROM => 'freepbx'
        };
    }

    my $data_for_xml = {
        SOFTWARES => \@modules
    };

    # Convert to XML
    my $xml = XMLout($data_for_xml, XMLDecl => 0, NoAttr => 1, RootName => undef);
    my $xml = XMLout($data);
    $logger->debug($xml);
    push @{ $inventory->{xmlroot}->{'CONTENT'} },{ $xml };
}

When running this part of script standalone, it returns stuff like :

  <SOFTWARES>
    <FROM>freepbx</FROM>
    <NAME>userman</NAME>
    <PUBLISHER>Sangoma</PUBLISHER>
    <VERSION>16.0.44</VERSION>
  </SOFTWARES>
  <SOFTWARES>
    <FROM>freepbx</FROM>
    <NAME>voicemail</NAME>
    <PUBLISHER>Sangoma</PUBLISHER>
    <VERSION>16.0.49</VERSION>
  </SOFTWARES>
  <SOFTWARES>
    <FROM>freepbx</FROM>
    <NAME>webrtc</NAME>
    <PUBLISHER>Sangoma</PUBLISHER>
    <VERSION>16.0.17</VERSION>
  </SOFTWARES>

But when running ocsinventory-agent -l=./, I don't see this output in the generated .ocs file

What am I doing wrong ? Is there some doc somewhere ?

Regards

in OCS Inventory NG plugins by (200 points)
edited by

Please log in or register to answer this question.

 
Powered by Question2Answer
...