forked from chrisridd/opendj-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decodecsn
executable file
·109 lines (73 loc) · 2.38 KB
/
decodecsn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/perl -w
use strict;
use warnings;
use bignum qw(hex);
use DateTime;
sub usage() {
print STDERR "Usage: $0 [-z timezone] csn [...]\n";
exit 1;
}
usage unless $#ARGV >= 0;
my $zone;
if ($ARGV[0] eq "-z") {
shift @ARGV;
$zone = shift @ARGV;
usage unless defined $zone;
}
$zone = DateTime::TimeZone->new(name => defined($zone) ? $zone : 'local');
foreach (@ARGV) {
if (my($ts,$id,$no) = m{^(................)(....)(........)$}) {
my $ts_dec = hex($ts); # Value is 64-bits hence using bignum
my $id_dec = hex($id);
my $no_dec = hex($no);
my $time = DateTime->from_epoch( epoch => $ts_dec / 1000 ); # UTC
$time->set_time_zone($zone);
my $ts_str = $time->strftime("%a %b %e %Y %H:%M:%S.%3N %Z");
print "CSN $_\n ts=$ts ($ts_dec) $ts_str\n id=$id ($id_dec)\n no=$no ($no_dec)\n";
next;
}
warn "Not a CSN: $_\n";
}
exit 0;
__END__
=head1 NAME
decodecsn - decode OpenDJ change sequence numbers
=head1 SYNOPSIS
decodecsn [-z timezone] csn [...]
=head1 DESCRIPTION
OpenDJ uses change sequence numbers to record information about replicated
changes. The CSN format is structured and can sometimes be usefully analyzed.
This tool decodes CSNs.
=head1 OPTIONS
=over
=item B<-z> use the following timezone name or offset instead of localtime to
display the date and time in the CSN.
=item B<csn> a change sequence number encoded in hex.
=back
=head1 EXAMPLES
$ decodecsn 0000014bcd10fe1562cd0083a482
CSN 0000014bcd10fe1562cd0083a482
ts=0000014bcd10fe15 (1425074617877) Fri Feb 27 2015 22:03:37.877 GMT
id=62cd (25293)
no=0083a482 (8627330)
$ decodecsn -z America/Los_Angeles 0000014bcd10fe1562cd0083a482
CSN 0000014bcd10fe1562cd0083a482
ts=0000014bcd10fe15 (1425074617877) Fri Feb 27 2015 14:03:37.877 PST
id=62cd (25293)
no=0083a482 (8627330)
$ decodecsn -z -0500 0000014bcd10fe1562cd0083a482
CSN 0000014bcd10fe1562cd0083a482
ts=0000014bcd10fe15 (1425074617877) Fri Feb 27 2015 17:03:37.877 -0500
id=62cd (25293)
no=0083a482 (8627330)
=head1 WARNING
The format of the CSN is undocumented and subject to change. This tool has been
tested with OpenDJ 2.4 and OpenDJ 2.6.
=head1 SEE ALSO
L<http://opendj.forgerock.org>
=head1 AUTHOR
Chris Ridd E<lt>[email protected]<gt>
=head1 COPYRIGHT
Copyright (c) 2012-2014 Chris Ridd. All rights reserved. This tool is free
software; you can redistribute it and/or modify it under the same terms as Perl
itself.