Skip to content

Commit

Permalink
Merge pull request #6 from simonkowallik/dev
Browse files Browse the repository at this point in the history
release 3.0
  • Loading branch information
simonkowallik authored Apr 1, 2019
2 parents 29b1be6 + 0950b09 commit c89b079
Show file tree
Hide file tree
Showing 18 changed files with 128 additions and 20 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

/README.md export-ignore
/LICENSE
/tests export-ignore
/.travis.yml export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ dist: xenial
language: generic

before_install:
- sudo apt-get install -y perl libxml-simple-perl
- sudo apt-get install -y perl libxml-simple-perl libxml2-utils
- openssl aes-256-cbc -K $encrypted_0321ff4314f5_key -iv $encrypted_0321ff4314f5_iv -in ./tests/cred.txt.enc -out ./tests/cred.txt -d


before_script:
- ./tests/test_setup.sh

script:
- ./tests/test_fileget.sh
- ./tests/test_fileget.sh
- ./tests/test_diagnostics.sh
- ./tests/test_qkviewdelete.sh
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ simon@bigip ~ $ ihac-diagnostics 2254055 | egrep -A3 "MEDIUM|^(P|H)"
simon@bigip ~ $ ihac-diagnostics 2254055 | egrep -A3 "HIGH|MEDIUM|^(P|H)"
```
Output JSON or XML for further processing
```sh
simon@bigip ~ $ ihac-diagnostics --json 2254055 | jq .
simon@bigip ~ $ ihac-diagnostics --xml 2254055 | xq
```
# Proxy Support
Specify environment variable before executing an ihac script
```sh
Expand Down
2 changes: 1 addition & 1 deletion ihac-auth
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#license: MIT
#author: Simon Kowallik <github simonkowallik.com>
#source: https://github.com/simonkowallik/iHAC
VERSION="2.1"
VERSION="3.0"
#
IHACAUTH="$HOME/.ihac/auth.jar"
if [[ ! -d "$HOME/.ihac" ]]; then mkdir "$HOME/.ihac"; fi
Expand Down
2 changes: 1 addition & 1 deletion ihac-commandlist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#license: MIT
#author: Simon Kowallik <github simonkowallik.com>
#source: https://github.com/simonkowallik/iHAC
VERSION="2.1"
VERSION="3.0"
#
IHACAUTH="$HOME/.ihac/auth.jar"
IHACPROXYFILE="$HOME/.ihac/IHACPROXY"
Expand Down
2 changes: 1 addition & 1 deletion ihac-commandrun
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#license: MIT
#author: Simon Kowallik <github simonkowallik.com>
#source: https://github.com/simonkowallik/iHAC
VERSION="2.1"
VERSION="3.0"
#
IHACAUTH="$HOME/.ihac/auth.jar"
IHACPROXYFILE="$HOME/.ihac/IHACPROXY"
Expand Down
61 changes: 54 additions & 7 deletions ihac-diagnostics
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#license: MIT
#author: Simon Kowallik <github simonkowallik.com>
#source: https://github.com/simonkowallik/iHAC
VERSION="2.1"
VERSION="3.0"
#
IHACAUTH="$HOME/.ihac/auth.jar"
IHACPROXYFILE="$HOME/.ihac/IHACPROXY"
Expand All @@ -14,9 +14,50 @@ function echoerr() { echo "$@" 1>&2; }
command -v perl >/dev/null 2>&1 || { echoerr "Error: $(basename $0) requires perl but it is not installed."; exit 1; }
command -v curl >/dev/null 2>&1 || { echoerr "Error: $(basename $0) requires curl but it is not installed."; exit 1; }

if [[ -n "$1" ]] && [[ "$1" =~ ^[0-9]+$ ]]

if [[ -n "$1" ]] && [[ "$1" == "--json" ]] && [[ "$2" =~ ^[0-9]+$ ]]
then
qkviewid="$2"
curl -si$IHACPROXY -H"Accept: application/vnd.f5.ihealth.api.v1.0+json" --user-agent "iHAC/$VERSION" \
--cookie "$IHACAUTH" --cookie-jar "$IHACAUTH" \
-o - https://ihealth-api.f5.com/qkview-analyzer/api/qkviews/$qkviewid/diagnostics?set=all \
| perl -e '
my $json;
while (<STDIN>) {
s/\r\n//g; s/\n//g; s/\r//g; s/\t/ /g;
if(m|http/1.. 200|gi) {$response=1} else {
if(m|http/1.. 30\d|gi) {print STDERR "Error: not authenticated.\n";exit 1}
if(m|http/1.. 404|gi) {print STDERR "Error: qkview ID not found.\n";exit 1}
}
if($response && m/^\{/g) {$json_response=1}
if($json_response) {$json .= $_}
}
print $json;
exit 0;
'
elif [[ -n "$1" ]] && [[ "$1" == "--xml" ]] && [[ "$2" =~ ^[0-9]+$ ]]
then
qkviewid="$2"
curl -si$IHACPROXY -H"Accept: application/vnd.f5.ihealth.api.v1.0+xml" --user-agent "iHAC/$VERSION" \
--cookie "$IHACAUTH" --cookie-jar "$IHACAUTH" \
-o - https://ihealth-api.f5.com/qkview-analyzer/api/qkviews/$qkviewid/diagnostics?set=all \
| perl -e '
my $xmldata;
while (<STDIN>) {
s/\r\n//g; s/\n//g; s/\r//g; s/\t/ /g;
if(m|http/1.. 200|gi) {$response=1} else {
if(m|http/1.. 30\d|gi) {print STDERR "Error: not authenticated.\n";exit 1}
if(m|http/1.. 404|gi) {print STDERR "Error: qkview ID not found.\n";exit 1}
}
if($response && m/<\?xml/gi) {$xml_response=1}
if($xml_response) {$xmldata .= $_}
}
print $xmldata;
exit 0;
' && exit 0
elif [[ -n "$1" ]] && [[ "$1" =~ ^[0-9]+$ ]]
then
curl -si$IHACPROXY -H"Accept: application/vnd.f5.ihealth.api.v1.0" --user-agent "iHAC/$VERSION" \
curl -si$IHACPROXY -H"Accept: application/vnd.f5.ihealth.api.v1.0+xml" --user-agent "iHAC/$VERSION" \
--cookie "$IHACAUTH" --cookie-jar "$IHACAUTH" \
-o - https://ihealth-api.f5.com/qkview-analyzer/api/qkviews/$1/diagnostics?set=all \
| perl -e '
Expand All @@ -40,17 +81,23 @@ then
$diag = $xml->{diagnostics}->{diagnostic};
foreach $hs ( sort { reverse($diag->{$a}->{run_data}->{h_importance}) cmp reverse($diag->{$b}->{run_data}->{h_importance}) } keys %{$diag} ) {
next if($diag->{$hs}->{run_data}->{match} eq "false");
$hs_r = $diag->{$hs}->{results}; $hs_s = $hs_r->{h_sols}->{solution};
$hs_r = $diag->{$hs}->{results};
my @hs_s;
foreach my $key (keys %{$hs_r->{h_sols}->{solution}}) {
if ($key eq "content") {push(@hs_s, $hs_r->{h_sols}->{solution}->{content});}
elsif ($key =~ /^K.*/) {push(@hs_s, $hs_r->{h_sols}->{solution}->{$key}->{content});}
}
$hs_s = $hs_r->{h_sols}->{solution}->{content};
print "* Severity: $diag->{$hs}->{run_data}->{h_importance} \tHeuristic: $hs_r->{h_name}\n";
print "* Title:\t$hs_r->{h_header}\n";
print "* Summary:\t$hs_r->{h_summary}\n";
print "* SOLs:\t\t"; if (ref($hs_s) eq "ARRAY") {print join(", ", @{$hs_s})} else {print $hs_s}
print "* SOLs:\t\t"; print join(", ", @hs_s);
print "\n\n";
}
exit 0;
'
' && exit 0
else
echoerr "Error: no qkview ID specified or not valid."
echoerr "Use: `basename $0` ID"
echoerr "Usage: `basename $0` [--json|--xml] ID"
exit 1
fi
2 changes: 1 addition & 1 deletion ihac-fileget
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#license: MIT
#author: Simon Kowallik <github simonkowallik.com>
#source: https://github.com/simonkowallik/iHAC
VERSION="2.1"
VERSION="3.0"
#
IHACAUTH="$HOME/.ihac/auth.jar"
IHACPROXYFILE="$HOME/.ihac/IHACPROXY"
Expand Down
2 changes: 1 addition & 1 deletion ihac-filelist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#license: MIT
#author: Simon Kowallik <github simonkowallik.com>
#source: https://github.com/simonkowallik/iHAC
VERSION="2.1"
VERSION="3.0"
#
IHACAUTH="$HOME/.ihac/auth.jar"
IHACPROXYFILE="$HOME/.ihac/IHACPROXY"
Expand Down
2 changes: 1 addition & 1 deletion ihac-qkviewadd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#license: MIT
#author: Simon Kowallik <github simonkowallik.com>
#source: https://github.com/simonkowallik/iHAC
VERSION="2.1"
VERSION="3.0"
#
IHACAUTH="$HOME/.ihac/auth.jar"
IHACPROXYFILE="$HOME/.ihac/IHACPROXY"
Expand Down
2 changes: 1 addition & 1 deletion ihac-qkviewdelete
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#license: MIT
#author: Simon Kowallik <github simonkowallik.com>
#source: https://github.com/simonkowallik/iHAC
VERSION="2.1"
VERSION="3.0"
#
IHACAUTH="$HOME/.ihac/auth.jar"
IHACPROXYFILE="$HOME/.ihac/IHACPROXY"
Expand Down
2 changes: 1 addition & 1 deletion ihac-qkviewget
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#license: MIT
#author: Simon Kowallik <github simonkowallik.com>
#source: https://github.com/simonkowallik/iHAC
VERSION="2.1"
VERSION="3.0"
#
IHACAUTH="$HOME/.ihac/auth.jar"
IHACPROXYFILE="$HOME/.ihac/IHACPROXY"
Expand Down
2 changes: 1 addition & 1 deletion ihac-qkviewlist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#license: MIT
#author: Simon Kowallik <github simonkowallik.com>
#source: https://github.com/simonkowallik/iHAC
VERSION="2.1"
VERSION="3.0"
#
IHACAUTH="$HOME/.ihac/auth.jar"
IHACPROXYFILE="$HOME/.ihac/IHACPROXY"
Expand Down
Binary file modified tests/qkview.tgz
Binary file not shown.
Binary file added tests/qkview_broken.tgz
Binary file not shown.
25 changes: 25 additions & 0 deletions tests/test_diagnostics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -ev

# test specific setup
qkviewid=$(<./qkviewid)


# check if Sevirity is part of the response
[[ $(./ihac-diagnostics $qkviewid | grep -e 'Severity: LOW' -e 'Severity: MEDIUM' -e 'Severity: HIGH' | wc -l) -gt 0 ]] || exit 1


# check if SOLs/K entries exist
[[ $(./ihac-diagnostics $qkviewid | grep -e 'SOLs:.*f5\.com' | wc -l) -gt 0 ]] || exit 1


# check if json is returned
./ihac-diagnostics --json $qkviewid | jq . >/dev/null 2>&1 || exit 1


# check if valid xml is returned
./ihac-diagnostics --xml $qkviewid | xmllint - >/dev/null 2>&1 || exit 1


# check behaviour when qkview does not exist
[[ $(./ihac-diagnostics 245245245 2>&1) == "Error: qkview ID not found." ]] || exit 1
17 changes: 17 additions & 0 deletions tests/test_qkviewdelete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -ev

# test specific setup
qkviewid=$(<./qkviewid)


# test qkview deletion
[[ "$(./ihac-qkviewdelete $qkviewid)" == "$qkviewid OK" ]] || exit 1


# check if qkview was removed from ihealth
./ihac-qkviewlist | grep $qkviewid && exist 1 || true


# check behaviour when qkview does not exist
[[ $(./ihac-qkviewdelete 245245245 2>&1) == "Error: qkview ID not found." ]] || exit 1
7 changes: 6 additions & 1 deletion tests/test_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ set -ev
# authenticate to ihealth
[[ "$(cat ./tests/cred.txt | ./ihac-auth)" == "OK" ]] || exit 1

# upload qkview
# upload working qkview
qkviewid=$(./ihac-qkviewadd ./tests/qkview.tgz | egrep -o '([0-9]+)')
echo "$qkviewid" > ./qkviewid
[[ -z $qkviewid ]] && echo "qkviewid empty" && exit 1

# upload broken qkview
broken_qkviewid=$(./ihac-qkviewadd ./tests/qkview.tgz | egrep -o '([0-9]+)')
echo "$broken_qkviewid" > ./broken_qkviewid
[[ -z $broken_qkviewid ]] && echo "broken_qkviewid empty" && exit 1

# wait for ihealth to finish analysis
while [[ "$(./ihac-filelist $qkviewid | wc -l)" -eq "0" ]]
do
Expand Down

0 comments on commit c89b079

Please sign in to comment.