@@ -19,7 +19,7 @@ import lib.disk # pylint: disable=C0413
1919
2020
2121__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
22- __version__ = '2025061503 '
22+ __version__ = '2025062501 '
2323
2424DESCRIPTION = """Compare two Icinga Director Baskets and highlight the differences."""
2525
@@ -48,6 +48,24 @@ def parse_args():
4848 return parser .parse_args ()
4949
5050
51+ def get_val (d ):
52+ if isinstance (d , bool ):
53+ tmp = str (d )
54+ elif isinstance (d , dict ):
55+ tmp = json .dumps (d )
56+ elif isinstance (d , float ):
57+ tmp = str (d )
58+ elif isinstance (d , int ):
59+ tmp = str (d )
60+ else :
61+ tmp = d
62+ if d is None :
63+ tmp = 'None'
64+ if len (tmp ) > 80 :
65+ return f'{ len (tmp )} chars in { type (d )} !'
66+ return tmp
67+
68+
5169def normalize_datafields (basket ):
5270 result = {}
5371 for d in basket ['Datafield' ].values ():
@@ -78,9 +96,10 @@ def normalize_commands(basket):
7896 result [uuid ][f'arguments.{ k } .{ kk } ' ] = vv
7997
8098 result [uuid ]['command' ] = d .get ('command' )
81- result [uuid ]['command' ] = result [uuid ]['command' ].replace ('C:\\ Program Files\\ icinga2\\ sbin\\ linuxfabrik\\ ' , '' )
82- result [uuid ]['command' ] = result [uuid ]['command' ].replace ('C:\\ ProgramData\\ icinga2\\ usr\\ lib64\\ nagios\\ plugins\\ ' , '' )
83- result [uuid ]['command' ] = result [uuid ]['command' ].replace ('/usr/lib64/nagios/plugins/' , '' )
99+ if result [uuid ]['command' ]:
100+ result [uuid ]['command' ] = result [uuid ]['command' ].replace ('C:\\ Program Files\\ icinga2\\ sbin\\ linuxfabrik\\ ' , '' )
101+ result [uuid ]['command' ] = result [uuid ]['command' ].replace ('C:\\ ProgramData\\ icinga2\\ usr\\ lib64\\ nagios\\ plugins\\ ' , '' )
102+ result [uuid ]['command' ] = result [uuid ]['command' ].replace ('/usr/lib64/nagios/plugins/' , '' )
84103 result [uuid ]['disabled' ] = d .get ('disabled' , False )
85104
86105 for f in d .get ('fields' , []):
@@ -404,8 +423,8 @@ def get_datafields_diff(diff):
404423 tmp ['uuid' ] = d ['uuid' ]
405424 tmp ['what' ] = 'val'
406425 tmp ['changed' ] = k .replace ("root['" , '' ).replace ("']" , '' )
407- tmp ['old_value' ] = v ['old_value' ]
408- tmp ['new_value' ] = v ['new_value' ]
426+ tmp ['old_value' ] = get_val ( v ['old_value' ])
427+ tmp ['new_value' ] = get_val ( v ['new_value' ])
409428 table_data .append (tmp )
410429 else :
411430 print (f'!!! Currently unhandled category { category } .' )
@@ -431,8 +450,8 @@ def get_commands_diff(diff):
431450 tmp ['uuid' ] = d ['uuid' ]
432451 tmp ['what' ] = 'val'
433452 tmp ['changed' ] = k .replace ("root['" , '' ).replace ("']" , '' )
434- tmp ['old_value' ] = v ['old_value' ]
435- tmp ['new_value' ] = v ['new_value' ]
453+ tmp ['old_value' ] = get_val ( v ['old_value' ])
454+ tmp ['new_value' ] = get_val ( v ['new_value' ])
436455 table_data .append (tmp )
437456 elif category == 'type_changes' :
438457 for k , v in changes .items ():
@@ -441,8 +460,8 @@ def get_commands_diff(diff):
441460 tmp ['uuid' ] = d ['uuid' ]
442461 tmp ['what' ] = 'type'
443462 tmp ['changed' ] = k .replace ("root['" , '' ).replace ("']" , '' )
444- tmp ['old_value' ] = f'{ v ["old_type" ]} ("{ v ["old_value" ]} ")'
445- tmp ['new_value' ] = f'{ v ["new_type" ]} ("{ v ["new_value" ]} ")'
463+ tmp ['old_value' ] = f'{ v ["old_type" ]} ("{ get_val ( v ["old_value" ]) } ")'
464+ tmp ['new_value' ] = f'{ v ["new_type" ]} ("{ get_val ( v ["new_value" ]) } ")'
446465 table_data .append (tmp )
447466 else :
448467 print (f'!!! Currently unhandled category { category } .' )
@@ -468,8 +487,8 @@ def get_host_templates_diff(diff):
468487 tmp ['uuid' ] = d ['uuid' ]
469488 tmp ['what' ] = 'val'
470489 tmp ['changed' ] = k .replace ("root['" , '' ).replace ("']" , '' )
471- tmp ['old_value' ] = v ['old_value' ]
472- tmp ['new_value' ] = v ['new_value' ]
490+ tmp ['old_value' ] = get_val ( v ['old_value' ])
491+ tmp ['new_value' ] = get_val ( v ['new_value' ])
473492 table_data .append (tmp )
474493 elif category == 'type_changes' :
475494 for k , v in changes .items ():
@@ -478,8 +497,8 @@ def get_host_templates_diff(diff):
478497 tmp ['uuid' ] = d ['uuid' ]
479498 tmp ['what' ] = 'type'
480499 tmp ['changed' ] = k .replace ("root['" , '' ).replace ("']" , '' )
481- tmp ['old_value' ] = f'{ v ["old_type" ]} ("{ v ["old_value" ]} ")'
482- tmp ['new_value' ] = f'{ v ["new_type" ]} ("{ v ["new_value" ]} ")'
500+ tmp ['old_value' ] = f'{ v ["old_type" ]} ("{ get_val ( v ["old_value" ]) } ")'
501+ tmp ['new_value' ] = f'{ v ["new_type" ]} ("{ get_val ( v ["new_value" ]) } ")'
483502 table_data .append (tmp )
484503 else :
485504 print (f'!!! Currently unhandled category { category } .' )
@@ -505,8 +524,8 @@ def get_service_templates_diff(diff):
505524 tmp ['uuid' ] = d ['uuid' ]
506525 tmp ['what' ] = 'val'
507526 tmp ['changed' ] = k .replace ("root['" , '' ).replace ("']" , '' )
508- tmp ['old_value' ] = v ['old_value' ]
509- tmp ['new_value' ] = v ['new_value' ]
527+ tmp ['old_value' ] = get_val ( v ['old_value' ])
528+ tmp ['new_value' ] = get_val ( v ['new_value' ])
510529 table_data .append (tmp )
511530 elif category == 'type_changes' :
512531 for k , v in changes .items ():
@@ -515,8 +534,28 @@ def get_service_templates_diff(diff):
515534 tmp ['uuid' ] = d ['uuid' ]
516535 tmp ['what' ] = 'type'
517536 tmp ['changed' ] = k .replace ("root['" , '' ).replace ("']" , '' )
518- tmp ['old_value' ] = f'{ v ["old_type" ]} ("{ v ["old_value" ]} ")'
519- tmp ['new_value' ] = f'{ v ["new_type" ]} ("{ v ["new_value" ]} ")'
537+ tmp ['old_value' ] = f'{ v ["old_type" ]} ("{ get_val (v ["old_value" ])} ")'
538+ tmp ['new_value' ] = f'{ v ["new_type" ]} ("{ get_val (v ["new_value" ])} ")'
539+ table_data .append (tmp )
540+ elif category == 'iterable_item_removed' :
541+ for k , v in changes .items ():
542+ tmp = {}
543+ tmp ['object_name' ] = d ['object_name' ]
544+ tmp ['uuid' ] = d ['uuid' ]
545+ tmp ['what' ] = 'item removed'
546+ tmp ['changed' ] = k .replace ("root['" , '' ).replace ("']" , '' )
547+ tmp ['old_value' ] = get_val (v )
548+ tmp ['new_value' ] = '-'
549+ table_data .append (tmp )
550+ elif category == 'iterable_item_added' :
551+ for k , v in changes .items ():
552+ tmp = {}
553+ tmp ['object_name' ] = d ['object_name' ]
554+ tmp ['uuid' ] = d ['uuid' ]
555+ tmp ['what' ] = 'item added'
556+ tmp ['changed' ] = k .replace ("root['" , '' ).replace ("']" , '' )
557+ tmp ['old_value' ] = '-'
558+ tmp ['new_value' ] = get_val (v )
520559 table_data .append (tmp )
521560 else :
522561 print (f'!!! Currently unhandled category { category } .' )
@@ -542,8 +581,8 @@ def get_service_sets_diff(diff):
542581 tmp ['uuid' ] = d ['uuid' ]
543582 tmp ['what' ] = 'val'
544583 tmp ['changed' ] = k .replace ("root['" , '' ).replace ("']" , '' ).replace ("services['" , '' ) + "']"
545- tmp ['old_value' ] = v ['old_value' ]
546- tmp ['new_value' ] = v ['new_value' ]
584+ tmp ['old_value' ] = get_val ( v ['old_value' ])
585+ tmp ['new_value' ] = get_val ( v ['new_value' ])
547586 table_data .append (tmp )
548587 elif category == 'type_changes' :
549588 for k , v in changes .items ():
@@ -552,8 +591,28 @@ def get_service_sets_diff(diff):
552591 tmp ['uuid' ] = d ['uuid' ]
553592 tmp ['what' ] = 'type'
554593 tmp ['changed' ] = k .replace ("root['" , '' ).replace ("']" , '' ).replace ("services['" , '' ) + "']"
555- tmp ['old_value' ] = f'{ v ["old_type" ]} ("{ v ["old_value" ]} ")'
556- tmp ['new_value' ] = f'{ v ["new_type" ]} ("{ v ["new_value" ]} ")'
594+ tmp ['old_value' ] = f'{ v ["old_type" ]} ("{ get_val (v ["old_value" ])} ")'
595+ tmp ['new_value' ] = f'{ v ["new_type" ]} ("{ get_val (v ["new_value" ])} ")'
596+ table_data .append (tmp )
597+ elif category == 'iterable_item_removed' :
598+ for k , v in changes .items ():
599+ tmp = {}
600+ tmp ['object_name' ] = d ['object_name' ]
601+ tmp ['uuid' ] = d ['uuid' ]
602+ tmp ['what' ] = 'item removed'
603+ tmp ['changed' ] = k .replace ("root['" , '' ).replace ("']" , '' ).replace ("services['" , '' ) + "']"
604+ tmp ['old_value' ] = get_val (v )
605+ tmp ['new_value' ] = '-'
606+ table_data .append (tmp )
607+ elif category == 'iterable_item_added' :
608+ for k , v in changes .items ():
609+ tmp = {}
610+ tmp ['object_name' ] = d ['object_name' ]
611+ tmp ['uuid' ] = d ['uuid' ]
612+ tmp ['what' ] = 'item added'
613+ tmp ['changed' ] = k .replace ("root['" , '' ).replace ("']" , '' ).replace ("services['" , '' ) + "']"
614+ tmp ['old_value' ] = '-'
615+ tmp ['new_value' ] = get_val (v )
557616 table_data .append (tmp )
558617 else :
559618 print (f'!!! Currently unhandled category { category } .' )
0 commit comments