##
UNAUTHENTICATED
operational
0
1
2
3
4
5
7
8
10
12
13
16
17
20
24
25
29
31
32
34
35
36
37
41
42
45
46
47
48
50
51
54
56
61
62
68
69
72
73
74
88
96
107
108
109
117
118
120
123
31
31
BRLE8
25
50
10
80
20
100
20
2
1
0
30
150
10
40
60
4
5
14
7
12
12
14
0
0
3
1
6
64
1
0
30
95
4
30
0
4
5
0
0
30
0
10
127
1
0
255
0
150
100
186
512
30
120
50
50
384
384
21
26
30
20
25
30
24
29
120
60
60
240
4
1
255
10
30
3
18
0
8
0
1
1
9
7
10
90
10
70
90
20
20
1
1
1
20
120
120
1
400
100
200
25
1
66947
66947
66947
8
0
65535
5
0
5
3
1
5
3
1
3
2
4
3
12
6
3
6
9
12
20
10
5
20
10
5
20
10
5
20
10
5
20
10
5
30
0
0
4152
0
15
1
10
5
128
0
127
##
##
perl -p0e "s/.*<\/managedObject>/$& x 100/se" testinsmall.xml > testin.xml
##
##
use XML::Twig;
$inputFile = 'testin.xml';
$outputFile = 'testout.xml';
$loop = 563;
$netType = "MNE-1v1";
$mx2G = "002";
$my2G = "02";
$objID = 1;
$bID = $firstElementID = 1;
$managedObjectsAmount = 0;
$someID = 0;
$segmentID = 0;
$header = "\n\n\n\n\n\n1 \nActualConfiguration \n \n";
$root = "\n\n\noperational
\n \n ";
$ending = "\n \n ";
my ($sec,$min,$hour,$day,$month,$yr19,@rest) = localtime(time);
open(OUT, ">", $outputFile) or die "cannot open dataOut.txt: $!";
print OUT $header;
print OUT $root;
for $i(1 .. $loop) {
$t= XML::Twig->new( twig_roots => { managedObject => \&handle_managedObject});
$t->parsefile($inputFile);
print "\nIteracja: $i / $loop \t-> OK\n";
$bID++;
$someID = 0;
}
print OUT $ending;
close (OUT);
print "\n----------------\nObjects managed: $managedObjectsAmount \n\n";
my ($sec2,$min2,$hour2,$day2,$month2,$yr192,@rest2) = localtime(time);
printStartTime();
printEndTime();
sub handle_managedObject {
my ($t, $element) = @_;
@fields = split(/\//, $element->{'att'}->{'distName'});
# distName="MNE-PET/*" - OK
if ($fields[0] ne $netType) {
$fields[0] = $netType;
}
# distName="MNE-PET/FLF-1000..1064" - OK
if ($fields[1] =~ /^FLF/) {
$fields[1] = "FLF-".$bID;
if (!$fields[2]) {
$element->first_child('p[@name="name"]')->set_text($fields[1]);
}
}
# distName="MNE-PET/FLF-*/WTF-1..65" -> / FLF
if ($fields[2] =~ /^WTF-\w+/) {
$fields[2] = "WTF-".$someID;
if (!$fields[3]) {
$fields[2] = "WTF-".++$someID;
$element->first_child('p[@name="name"]')->set_text($fields[2]);
}
}
# distName="MNE-PET/FLF-*/WTF-*/XLS-1..6" -> /WTF
if (($fields[3] =~ /^XLS-\w+/) && (!$fields[4])) {
@fieldsFLF = split(/-/, $fields[1]);
@fieldsWTF = split(/-/, $fields[2]);
@fieldsXLS = split(/-/, $fields[3]);
$cId = $fieldsWTF[1].$fieldsXLS[1];
$element->first_child('p[@name="name"]')->set_text($fields[3]);
$element->first_child('p[@name="cId"]')->set_text($cId);
$element->first_child('p[@name="locAreaId1"]')->set_text($fieldsFLF[1]);
$element->first_child('p[@name="locAreaId2"]')->set_text($mx2G);
$element->first_child('p[@name="locAreaId3"]')->set_text($my2G);
if ($fieldsXLS[1] == 1) {
$element->first_child('p[@name="masterWTF"]')->set_text(1);
$element->first_child('p[@name="segmentId"]')->set_text(++$segmentID);
}
else {
$element->first_child('p[@name="masterWTF"]')->set_text(0);
$element->first_child('p[@name="segmentId"]')->set_text($segmentID);
}
}
$element->{'att'}->{'distName'} = join ('/',@fields);
$element->{'att'}->{'id'} = $objID++;
$element->set_pretty_print( 'indented');
$element->print(\*OUT) or die "Failed to write managedObject to output XML file:$!\n";
$managedObjectsAmount++;
}
sub printToFile {
$element->set_pretty_print( 'indented');
$element->flush(\*OUT) or die "Failed to write element output XML file:$!\n";
}
sub printStartTime {
print "START Time:\t".sprintf("%02d",$hour).":".sprintf("%02d",$min).":".sprintf("%02d",$sec);###To print the current time
print "\t$day-".++$month. "-".($yr19+1900)."\n"; ####To print date format as expected
}
sub printEndTime {
print "END Time:\t".sprintf("%02d",$hour2).":".sprintf("%02d",$min2).":".sprintf("%02d",$sec2);###To print the current time
print "\t$day2-".++$month2. "-".($yr192+1900)."\n"; ####To print date format as expected
}