aboutsummaryrefslogtreecommitdiff
path: root/rcynic/show.awk
blob: 84d33cda3a266abc1346050d0913c4cc43141b88 (plain) (blame)
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
# $Id$
#
# Copyright (C) 2010-2011  Internet Systems Consortium, Inc. ("ISC")
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

# Prettyprint tab-delimited rcynic summary data.  This is intended as
# a postprocessor for show.xsl.

BEGIN {
  FS = "\t";
  label[++nlabels] = "hostname";
  head["hostname", 1] = "Repository";
  head["hostname", 2] = "Host";
  width["hostname"] = length(head["hostname", 1]);
}

!NF {
  got_labels = 1;
  next;
}

!got_labels {
  label[++nlabels] = $1;
  nh = split($2, h, /[ \t]+/);
  for (i = 1; i <= nh; i++) {
    head[$1, i] = h[i];
    if (length(h[i]) > width[$1])
      width[$1] = length(h[i]);
  }
}

got_labels && $3 ~ /^rsync:\/\/.+/ {
  hostname = $3;
  sub(/^rsync:\/\//, "", hostname);
  sub(/\/.*$/, "", hostname);
  if (!seen[hostname])
    seen[hostname] = ++nhostnames;
  data[hostname, $2]++;
  total[$2]++;
  if (length(hostname) > width["hostname"])
    width["hostname"] = length(hostname);
}

END {

  for (i = 1;; i++) {
    blank = 1;
    for (j = 1; j <= nlabels; j++)
      if (head[label[j], i] && (j == 1 || total[label[j]] > 0))
	blank = 0;
    if (blank)
      break;
    for (j = 1; j <= nlabels; j++) {
      if (j == 1)
	printf "%-*s", width[label[j]], head[label[j], i];
      else if (total[label[j]] > 0)
	printf "   %*s", width[label[j]], head[label[j], i];
    }
    print "";
  }

  for (i in seen)
    hostnames[seen[i]] = i;

  for (i = 1; i <= nhostnames; i++) {
    for (j = 1; j <= nlabels; j++) {
      if (j == 1)
	printf "%-*s", width[label[j]], hostnames[i];
      else if (total[label[j]] > 0)
	printf "   %*s", width[label[j]], data[hostnames[i], label[j]];
    }
    print "";
  }

  for (j = 1; j <= nlabels; j++) {
    if (j == 1)
      printf "%-*s", width[label[j]], "Total";
    else if (total[label[j]] > 0)
      printf "   %*s", width[label[j]], total[label[j]];
  }
  print "";
}