Debian Codegraph @

connectors/vmware/src/centreon/script/centreon_vmware_convert_config_file

raw
1 #!/usr/bin/perl
2 # Copyright 2024 Centreon (http://www.centreon.com/)
3 #
4 # Centreon is a full-fledged industry-strength solution that meets
5 # the needs in IT infrastructure and application monitoring for
6 # service performance.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19
20 use strict;
21 use warnings FATAL => 'all';
22 use JSON;
23 use Data::Dumper;
24
25 die "Usage: centreon_vmware_convert_config_file /etc/centreon/centreon_vmware.pm > /etc/centreon/centreon_vmware.json" if (scalar(@ARGV) < 1);
26 my $config_file = $ARGV[0];
27
28 die "Config file $config_file does not exist.\n" if (! -f $config_file);
29
30 our %centreon_vmware_config;
31 require($config_file) or die "Error while loading file $config_file";
32
33 my $new_config_structure = {
34 vsphere_server => []
35 };
36
37 for my $config_entry_key (keys %centreon_vmware_config){
38 if ($config_entry_key eq 'vsphere_server') {
39 for my $server_config_entry_key (keys %{$centreon_vmware_config{vsphere_server}}) {
40 my $config_entry_content = $centreon_vmware_config{vsphere_server}->{$server_config_entry_key};
41 $config_entry_content->{name} = $server_config_entry_key;
42 push @{$new_config_structure->{vsphere_server}}, $config_entry_content;
43 }
44 } else {
45 $new_config_structure->{$config_entry_key} = $centreon_vmware_config{$config_entry_key};
46 }
47 }
48
49 my $new_json_config = JSON->new->utf8(1)->pretty(1)->encode($new_config_structure) or die "Unable to convert this object to JSON:\n" . Dumper($new_config_structure);
50
51 print($new_json_config);
52
53 exit(0);
54