Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

Commit 4ee1247

Browse files
committed
Convert md 2 pdf
1 parent 1c7f644 commit 4ee1247

36 files changed

+2447
-285
lines changed

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ The following programs must be installed on the observer machine:
9898
* golang >= 1.8 (no binaries are shipped at the moment)
9999
* awk
100100
* sed
101+
* pandoc *
102+
* wkhtmltopdf *
103+
104+
Pandoc and wkhtmltopdf optional, they need for generating HTML and PDF versions
105+
of report (see `--pdf` and `--html`).
101106

102107
Nothing special has to be installed on the observed machines. However, these
103108
machines must run Linux (again: modern RHEL/CentOS or Debian/Ubuntu; others
@@ -107,6 +112,33 @@ should work as well, but are not yet tested).
107112

108113
## How to Install
109114

115+
#### 1. Install required programs
116+
117+
Ubuntu/Debian:
118+
```
119+
sudo apt-get update
120+
sudo apt-get install postgresql
121+
sudo apt-get install coreutils
122+
sudo apt-get install jq
123+
sudo apt-get install golang
124+
# Optional
125+
sudo apt install pandoc
126+
sudo apt-get install wkhtmltopdf
127+
```
128+
129+
MacOS (assuming that Homebrew is installed):
130+
```
131+
brew install postgresql
132+
brew install coreutils
133+
brew install jq
134+
brew install golang
135+
# Optional
136+
brew install pandoc
137+
brew install Caskroom/cask/wkhtmltopdf
138+
```
139+
140+
#### 2. Clone this repo
141+
110142
Use `git clone`. This is the only method of installation currently supported.
111143

112144
## Example of Use

checkup

+8-1
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ glue_md_reports() {
777777
title="${title%"${title##*[![:space:]]}"}"
778778
checkId=$(echo $title | cut -c 1-4)
779779
tableOfContents="$tableOfContents\n[$title](#postgres-checkup_$checkId) "
780-
content="$content\n---\n<a name=\"postgres-checkup_$checkId\"></a>\n[Table of contents](#postgres-checkup_top)"
780+
content="$content\n\n\n---\n<a name=\"postgres-checkup_$checkId\"></a>\n[Table of contents](#postgres-checkup_top)"
781781
report=$(cat "${cur_report}")
782782
content="$content\n$report"
783783
done
@@ -1110,6 +1110,13 @@ run_checks() {
11101110
echo " '${MD_REPORTS_DIR}/${FULL_REPORT_FNAME}'"
11111111
msg
11121112
fi
1113+
1114+
if [[ "$PDF" == "true" ]]; then
1115+
./resources/md2pdf.sh --pdf ${MD_REPORTS_DIR}/${FULL_REPORT_FNAME}
1116+
fi
1117+
if [[ "$HTML" == "true" ]]; then
1118+
./resources/md2pdf.sh --html ${MD_REPORTS_DIR}/${FULL_REPORT_FNAME}
1119+
fi
11131120
}
11141121

11151122
######### COMMANDS WRAPPERS ###########

pghrep/src/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func loadTemplates() *template.Template {
169169
tplFuncMap["RawFloatFormat"] = RawFloatFormat
170170
tplFuncMap["Int"] = Int
171171
tplFuncMap["EscapeQuery"] = EscapeQuery
172+
tplFuncMap["WordWrap"] = WordWrap
172173

173174
templates, err = template.New("").Funcs(tplFuncMap).ParseFiles(allFiles...)
174175
if err != nil {

pghrep/src/reportutils.go

+26-2
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,43 @@ func Br(s interface{}) string {
4141
return strings.Join(strings.Split(str, ","), ", ")
4242
}
4343

44+
/* Divide text to rows by given row length
45+
*/
46+
func WordWrap(s string, limit int) string {
47+
srcStr := s //strings.Join(strings.Split(s, "\n"), " ")
48+
str := ""
49+
pos := 0
50+
for _, c := range srcStr {
51+
if pos > limit && (c == ' ' || c == ',' || c == '(') {
52+
pos = 0
53+
str = str + string(c) + "\n"
54+
} else {
55+
str = str + string(c)
56+
}
57+
pos++
58+
}
59+
return str
60+
}
4461

4562
/* Escape Markdown symbols in a SQL query,
4663
* convert to a single line
4764
*/
4865
func EscapeQuery(s interface{}) string {
4966
str := pyraconv.ToString(s)
50-
str = strings.Join(strings.Split(str, "\n"), " ")
67+
68+
str = strings.Join(strings.Split(str, "\n \n"), "<br/>")
5169
str = strings.Join(strings.Split(str, " "), "&nbsp;")
5270
str = strings.Join(strings.Split(str, "*"), "\\*")
5371
str = strings.Join(strings.Split(str, "_"), "\\_")
5472
str = strings.Join(strings.Split(str, "-"), "\\-")
73+
str = strings.Join(strings.Split(str, "~"), "\\~")
5574
str = strings.Join(strings.Split(str, "`"), "\\`")
56-
str = strings.Join(strings.Split(str, "|"), "\\|")
75+
// str = strings.Join(strings.Split(str, "\""), "&#34;")
76+
str = strings.Join(strings.Split(str, "|"), "&#448;")
77+
str = strings.Join(strings.Split(str, "\n\n"), "<br/>")
78+
str = strings.Join(strings.Split(str, "\n\r"), "<br/>")
79+
str = strings.Join(strings.Split(str, "\n"), "<br/>")
80+
str = strings.Join(strings.Split(str, "<br/><br/>"), "<br/>")
5781
return str
5882
}
5983

pghrep/templates/A001.tpl

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ Data collected: {{ DtFormat .timestamptz }}
66
{{ if gt (len .results) 2 }} {{/* Min 2 hosts + "_keys" item */}}
77
### Operating System by hosts ###
88

9-
Host| Operating System | Kernel
10-
----|------------------|--------
9+
| Host| Operating System | Kernel |
10+
|----|------------------|--------|
1111
{{- if (index .results .hosts.master) }}
1212
{{- if (index (index .results .hosts.master) "data") }}
1313
{{- if (index (index (index .results .hosts.master) "data").virtualization) }}
14-
{{ .hosts.master }}|
14+
| {{ .hosts.master }} |
1515
{{- (index (index (index (index .results .hosts.master) "data").virtualization) "Operating System") }} |
16-
{{- (index (index (index (index .results .hosts.master) "data").virtualization) "Kernel") }}
16+
{{- (index (index (index (index .results .hosts.master) "data").virtualization) "Kernel") }} |
1717
{{- end -}}
1818
{{- end -}}
1919
{{- end -}}

pghrep/templates/A003.tpl

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ Data collected: {{ DtFormat .timestamptz }}
66
{{ if (index .results .hosts.master) }}
77
{{ if (index (index .results .hosts.master) "data") }}
88
### Master (`{{.hosts.master}}`) ###
9-
&#9660;&nbsp;Category | Setting | Value | Unit | Pretty value
10-
---------|---------|-------|------|--------------
9+
| &#9660;&nbsp;Category | Setting | Value | Unit | Pretty value |
10+
|---------|---------|-------|------|--------------|
1111
{{ range $i, $key := (index (index (index .results .hosts.master) "data") "_keys") }}
1212
{{- $value := (index (index (index $.results $.hosts.master) "data") $key) -}}
13-
{{ $value.category }}|[{{ $key }}](https://postgresqlco.nf/en/doc/param/{{ $key }}) | {{ Br $value.setting }} | {{ if $value.unit }}{{ $value.unit }} {{ end }} | {{ UnitValue $value.setting $value.unit }}
13+
| {{ $value.category }}|[{{ $key }}](https://postgresqlco.nf/en/doc/param/{{ $key }}) | {{ Br $value.setting }} | {{ if $value.unit }}{{ $value.unit }} {{ end }} | {{ UnitValue $value.setting $value.unit }} |
1414
{{ end }}
1515
{{- else -}}{{/*Master data*/}}
1616
No data

pghrep/templates/A004.tpl

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ Data collected: {{ DtFormat .timestamptz }}
77
{{ if (index (index .results .hosts.master) "data") }}
88
### Master (`{{.hosts.master}}`) ###
99
{{ if (index (index (index .results .hosts.master) "data") "general_info") }}
10-
Indicator | Value
11-
-----------|-------
10+
| Indicator | Value |
11+
|-----------|-------|
1212
{{ range $i, $key := (index (index (index (index .results .hosts.master) "data") "general_info") "_keys") }}
1313
{{- $value := (index (index (index (index $.results $.hosts.master) "data") "general_info") $key) -}}
14-
{{ $key }} | {{ Nobr (index $value "value") }}
14+
| {{ $key }} | {{ Nobr (index $value "value") }} |
1515
{{ end }}
1616
{{- end -}}
1717
{{ if (index (index (index .results .hosts.master) "data") "database_sizes") }}
1818
#### Databases sizes ####
19-
Database | &#9660;&nbsp;Size
20-
---------|------
19+
| Database | &#9660;&nbsp;Size |
20+
|---------|------|
2121
{{ range $i, $key := (index (index (index (index .results .hosts.master) "data") "database_sizes") "_keys") }}
2222
{{- $value := (index (index (index (index $.results $.hosts.master) "data") "database_sizes") $key) -}}
23-
{{ $key }} | {{ ByteFormat $value 2 }}
23+
| `{{ $key }}` | {{ ByteFormat $value 2 }} |
2424
{{ end }}
2525
{{- end -}}
2626
{{- end -}}
@@ -32,11 +32,11 @@ Database | &#9660;&nbsp;Size
3232
{{ range $skey, $host := .hosts.replicas }}
3333
#### Replica (`{{ $host }}`) ####
3434
{{ if (index $.results $host) }}
35-
Indicator | Value
36-
-----------|-------
35+
| Indicator | Value |
36+
|-----------|-------|
3737
{{ range $i, $key := (index (index (index (index $.results $host) "data") "general_info") "_keys") }}
3838
{{- $value := (index (index (index (index $.results $host) "data") "general_info") $key) -}}
39-
{{ $key }} | {{ Nobr (index $value "value") }}
39+
| {{ $key }} | {{ Nobr (index $value "value") }} |
4040
{{ end }}
4141
{{- else -}}
4242
No data

pghrep/templates/A005.tpl

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ Data collected: {{ DtFormat .timestamptz }}
66
{{ if (index .results .hosts.master) }}
77
{{ if (index (index .results .hosts.master) "data") }}
88
### Master (`{{.hosts.master}}`) ###
9-
&#9660;&nbsp;Database | Extension name | Installed version | Default version | Is old
10-
---------|----------------|-------------------|-----------------|--------
9+
| &#9660;&nbsp;Database | Extension name | Installed version | Default version | Is old |
10+
|---------|----------------|-------------------|-----------------|--------|
1111
{{ range $d, $db := (index (index (index .results .hosts.master) "data") "_keys") -}}
1212
{{- $dbData := (index (index (index $.results $.hosts.master) "data") $db) -}}
1313
{{- range $de, $dbext := (index $dbData "_keys") -}}
1414
{{- $extData := (index $dbData $dbext) -}}
15-
{{ $db }} | {{ $dbext }} | {{ $extData.installed_version }} | {{ $extData.default_version }} | {{ $extData.is_old }}
15+
| `{{ $db }}` | `{{ $dbext }}` | {{ $extData.installed_version }} | {{ $extData.default_version }} | {{ $extData.is_old }} |
1616
{{ end -}}
1717
{{ end -}}
1818
{{ else }}

pghrep/templates/A006.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Data collected: {{ DtFormat .timestamptz }}
66
### Settings (pg_settings) that Differ ###
77
{{ if (index .diffData "pg_settings") }}
88
&#9660;&nbsp;Setting | {{.hosts.master}} {{ range $skey, $host := .hosts.replicas }}| {{ $host }} {{ end }}
9-
--------|-------{{ range $skey, $host := .hosts.replicas }}|-------- {{ end }}
10-
{{ range $key, $value := (index .diffData "pg_settings") }}{{ $key }} {{ range $key, $value := $value }} |{{ if and ( ne (index $value "value") "-1") ( ne (index $value "value") "0") (index $value "unit") }}{{ if (UnitValue (index $value "value") (index $value "unit")) }}{{ UnitValue (index $value "value") (index $value "unit") }}{{else}}{{(index $value "value")}} {{(index $value "unit") }}{{end}}{{else}}{{ index $value "value" }}{{ end }}{{ end }}
9+
|--------|-------{{ range $skey, $host := .hosts.replicas }}|-------- {{ end }}|
10+
{{ range $key, $value := (index .diffData "pg_settings") }}| [{{ $key }}](https://postgresqlco.nf/en/doc/param/{{ $key }}) | {{ Br $key }}{{ range $key, $value := $value }} |{{ if and ( ne (index $value "value") "-1") ( ne (index $value "value") "0") (index $value "unit") }}{{ if (UnitValue (index $value "value") (index $value "unit")) }}{{ UnitValue (index $value "value") (index $value "unit") }}{{else}}{{(index $value "value")}} {{(index $value "unit") }}{{end}}{{else}}{{ index $value "value" }}{{ end }}{{ end }} |
1111
{{ end }}
1212
{{ else }}
1313
No differences in `pg_settings` are found.

pghrep/templates/A007.tpl

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Data collected: {{ DtFormat .timestamptz }}
66
{{ if (index .results .hosts.master) }}
77
{{ if (index (index .results .hosts.master) "data") }}
88
### Master (`{{.hosts.master}}`) ###
9-
Source | Settings specified | List of settings
10-
-------|--------------------|-----------------
11-
{{ range $key, $value := (index (index (index .results .hosts.master) "data") "changes") }}{{ if $value.sourcefile }}{{ $value.sourcefile }}{{ else}}default{{ end }} | {{ $value.count }} | {{ if $value.examples}} {{ if (gt (len $value.examples) 0) }}{{ range $skey, $sname := (index $value "examples") }}{{ $sname }} {{ end }} {{ end }}
12-
{{ end }}{{ end }}
9+
| Source | Settings count | Changed settings |
10+
|-------|----------------|-----------------|
11+
{{ range $key, $value := (index (index (index .results .hosts.master) "data") "changes") }}| {{ if $value.sourcefile }}{{ $value.sourcefile }}{{ else}}default{{ end }} | {{ $value.count }} | {{ if $value.examples}} {{ if (gt (len $value.examples) 0) }}{{ range $skey, $sname := (index $value "examples") }}{{ $sname }} {{ end }} {{ end }}
12+
{{ end }}|{{ end }}
1313
{{ end }}
1414
{{ end }}
1515
{{ end }}
@@ -19,11 +19,11 @@ Source | Settings specified | List of settings
1919
{{ range $skey, $host := .hosts.replicas }}
2020
#### Replica (`{{ $host }}`) ####
2121
{{ if (index $.results $host) }}
22-
Source | Settings specified | List of settings
23-
-------|--------------------|-----------------
24-
{{ range $key, $value := (index (index (index $.results $host) "data") "changes") }}{{ if $value.sourcefile }}{{ $value.sourcefile }}{{ else}}default{{ end }} | {{ $value.count }} | {{ if $value.examples}} {{ if (gt (len $value.examples) 0) }}{{ range $skey, $sname := (index $value "examples") }}{{ $sname }} {{ end }} {{ end }}
25-
{{ end }}{{ end }}
26-
{{ else }}
22+
| Source | Settings count | Changed settings |
23+
|-------|----------------|-----------------|
24+
{{ range $key, $value := (index (index (index $.results $host) "data") "changes") }}|{{ if $value.sourcefile }}{{ $value.sourcefile }}{{ else}}default{{ end }} | {{ $value.count }} | {{ if $value.examples}} {{ if (gt (len $value.examples) 0) }}{{ range $skey, $sname := (index $value "examples") }}{{ $sname }} {{ end }} {{ end }}
25+
{{ end }}|{{ end }}
26+
{{ else }}
2727
No data
2828
{{ end}}{{ end }}{{ end }}
2929

pghrep/templates/A008.tpl

+35-35
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,33 @@ Data collected: {{ DtFormat .timestamptz }}
99
### Master (`{{.hosts.master}}`) ###
1010

1111
#### System directories ####
12-
Device | FS Type | Size | Available | Usage | Used | Mount Point
13-
-------|---------|------|-----------|-----|------|-------------
12+
| Device | FS Type | Size | Available | Usage | Used | Mount Point |
13+
|-------|---------|------|-----------|-----|------|-------------|
1414
{{ range $i, $name := (index (index (index (index .results .hosts.master) "data") "fs_data") "_keys") -}}
1515
{{- $value := (index (index (index (index $.results $.hosts.master) "data") "fs_data") $name) -}}
16-
{{ $value.device}}|
16+
| {{ $value.device}}|
1717
{{- $value.fstype}}|
1818
{{- $value.size}}|
1919
{{- $value.avail}}|
2020
{{- $value.use_percent}}|
2121
{{- $value.used}}|
22-
{{- $value.mount_point}}
22+
{{- $value.mount_point}} |
2323
{{ end }}{{/* end of range $i, $name := */}}
2424

2525
#### Database directories ####
26-
Name | FS Type | Size | Available | Usage | Used | Mount Point | Path | Device
27-
-----|---------|------|-----------|-----|------|-------------|------|-------
26+
| Name | FS Type | Size | Available | Usage | Used | Mount Point | Path | Device |
27+
|-----|---------|------|-----------|-----|------|-------------|------|-------|
2828
{{ range $i, $name := (index (index (index (index .results .hosts.master) "data") "db_data") "_keys") -}}
2929
{{- $value := (index (index (index (index $.results $.hosts.master) "data") "db_data") $name) -}}
30-
{{ $name }}|
31-
{{- $value.fstype}}|
32-
{{- $value.size}}|
33-
{{- $value.avail}}|
34-
{{- $value.use_percent}}|
35-
{{- $value.used}}|
36-
{{- $value.mount_point}}|
37-
{{- $value.path}}|
38-
{{- $value.device}}
30+
| {{ $name }} |
31+
{{- $value.fstype}} |
32+
{{- $value.size}} |
33+
{{- $value.avail}} |
34+
{{- $value.use_percent}} |
35+
{{- $value.used}} |
36+
{{- $value.mount_point}} |
37+
{{- $value.path}} |
38+
{{- $value.device}} |
3939
{{ end }}{{/* end of range $i, $name := */}}
4040

4141
{{ end }}{{/* end of if .hosts.master data */}}
@@ -49,33 +49,33 @@ Name | FS Type | Size | Available | Usage | Used | Mount Point | Path | Device
4949
#### Replica (`{{ $host }}`) ####
5050

5151
#### System directories ####
52-
Device | FS Type | Size | Available | Usage | Used | Mount Point
53-
-------|---------|------|-----------|-----|------|-------------
52+
| Device | FS Type | Size | Available | Usage | Used | Mount Point |
53+
|-------|---------|------|-----------|-----|------|-------------|
5454
{{ range $i, $name := (index (index (index (index $.results $host) "data") "fs_data") "_keys") -}}
5555
{{- $value := (index (index (index (index $.results $host) "data") "fs_data") $name) -}}
56-
{{ $value.device}}|
57-
{{- $value.fstype}}|
58-
{{- $value.size}}|
59-
{{- $value.avail}}|
60-
{{- $value.use_percent}}|
61-
{{- $value.used}}|
62-
{{- $value.mount_point}}
56+
| {{ $value.device}} |
57+
{{- $value.fstype}} |
58+
{{- $value.size}} |
59+
{{- $value.avail}} |
60+
{{- $value.use_percent}} |
61+
{{- $value.used}} |
62+
{{- $value.mount_point}} |
6363
{{ end }}{{/* range $i, $name := */}}
6464

6565
#### Database directories ####
66-
Name | FS Type | Size | Available | Usage | Used | Mount Point | Path | Device
67-
-----|---------|------|-----------|-----|------|-------------|------|-------
66+
| Name | FS Type | Size | Available | Usage | Used | Mount Point | Path | Device |
67+
|-----|---------|------|-----------|-----|------|-------------|------|-------|
6868
{{ range $i, $name := (index (index (index (index $.results $host) "data") "db_data") "_keys") -}}
6969
{{- $value := (index (index (index (index $.results $host) "data") "db_data") $name) -}}
70-
{{ $name }}|
71-
{{- $value.fstype}}|
72-
{{- $value.size}}|
73-
{{- $value.avail}}|
74-
{{- $value.use_percent}}|
75-
{{- $value.used}}|
76-
{{- $value.mount_point}}|
77-
{{- $value.path}}|
78-
{{- $value.device}}
70+
| {{ $name }} |
71+
{{- $value.fstype}} |
72+
{{- $value.size}} |
73+
{{- $value.avail}} |
74+
{{- $value.use_percent}} |
75+
{{- $value.used}} |
76+
{{- $value.mount_point}} |
77+
{{- $value.path}} |
78+
{{- $value.device}} |
7979
{{ end }}{{/* range $i, $name := */}}
8080

8181
{{ end }}{{/* if (index $.results $host) */}}

pghrep/templates/D002.tpl

+11-9
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ Data collected: {{ DtFormat .timestamptz }}
77
### Master (`{{.hosts.master}}`) ###
88
{{ range $i, $key := (index (index (index .results .hosts.master) "data") "_keys") }}
99
{{- $value := (index (index (index $.results $.hosts.master) "data") $key) -}}
10-
### {{ $key }}
11-
Utility | Availability
12-
--------|--------------
10+
### {{ $key }} ###
11+
| Utility | Availability |
12+
|--------|--------------|
1313
{{- range $k, $util_name := (index (index $value) "_keys") }}
14-
{{ $util_name }} | {{ (index (index $value) $util_name) }}
15-
{{- end }}{{/* range values */}}
14+
| {{ $util_name }} | {{ (index (index $value) $util_name) }} |
15+
{{- end }}{{/* range values */}}
16+
1617
{{ end }}{{/* range data */}}
1718
{{ end }}{{/* if master host data*/}}
1819
{{ end }}{{/* if master results*/}}
@@ -25,11 +26,12 @@ Utility | Availability
2526
{{ range $i, $key := (index (index (index $.results $host) "data") "_keys") }}
2627
{{- $value := (index (index (index $.results $host) "data") $key) -}}
2728
### {{ $key }}
28-
Utility | Availability
29-
--------|--------------
29+
| Utility | Availability |
30+
|--------|--------------|
3031
{{- range $k, $util_name := (index (index $value) "_keys") }}
31-
{{ $util_name }} | {{ (index (index $value) $util_name) }}
32-
{{- end }}{{/* range values */}}
32+
| {{ $util_name }} | {{ (index (index $value) $util_name) }} |
33+
{{- end }}{{/* range values */}}
34+
3335
{{ end }}{{/* range data */}}
3436
{{ end }}{{/* if host data*/}}
3537
{{ end }}{{/* range replicas*/}}

0 commit comments

Comments
 (0)