Skip to content

Commit

Permalink
added ncp-diag and ncp-report
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoparker committed Nov 18, 2017
1 parent 2c25fa9 commit ede912f
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 45 deletions.
46 changes: 2 additions & 44 deletions .github/issue_template.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!--
Thanks for reporting issues back to NextCloudPi!
Here you can file questions, bugs and feature requests
Here you can file bugs and feature requests
If there is an important security issue that has gone unnoticed, please send a private email to nacho _at_ ownyourbits.com
Expand All @@ -20,46 +20,4 @@ If you are running into problems, please fill out the following information. For
Keep in mind that many problems come from faulty power sources and corrupted SD cards, so make sure this is not the case for you before reporting.
-->

### What version of NextCloudPi are you using? ( eg: v0.17.2 )

### What is the base image that you installed on the SD card? ( eg: NextCloudPi_07-21-17 )

You can discover this by executing

```
cat /usr/local/etc/ncp-baseimage
```

### Expected behavior

### Actual behaviour

### Steps to reproduce, from a freshly installed image

### Include logs
<details>
<summary>Nextcloud logs</summary>

```
Login as admin user into your Nextcloud and copy here the logs from
https://example.com/index.php/settings/admin/logging
If you don't have access to the web interface, open a terminal session and paste the last 100 lines of /var/www/nextcloud/data/nextcloud.log
```
</details>
<details>
<summary>Apache logs</summary>

```
Paste the output of `systemctl status apache2`
Paste the output of `tail -n 100 /var/log/apache2/*.log`
```
</details>
<details>
<summary>mariaDB logs</summary>

```
Paste the output of `systemctl status mysqld`
Paste the output of `tail -n 100 /var/log/mysql/*.log`
```
</details>
Paste the output of `sudo ncp-report`
106 changes: 106 additions & 0 deletions bin/ncp-diag
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/bash

# NextCloudPi diagnostics report
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
#
# Usage:
# sudo ncp-diag
#
# More at https://ownyourbits.com
#

# Distro, NCP version and tag
echo "NextCloudPi version|$( cat /usr/local/etc/ncp-version )"
echo "NextCloudPi image|$( cat /usr/local/etc/ncp-baseimage )"
echo "distribution|$( cat /etc/issue )"

# Data
DATADIR="$( grep datadirectory /var/www/nextcloud/config/config.php |
awk '{ print $3 }' | grep -oP "[^']*[^']" | head -1 )"
test -d "$DATADIR" || DIRINFO=" (doesn't exist)"
USBDEVS="$( lsblk -S -o NAME,TRAN | awk '{ if ( $2 == "usb" ) print $1; }' | tr '\n' ' ' )"
[[ "$USBDEVS" == "" ]] && USBDEVS="none"

echo "automount|$( grep "^ACTIVE_" /usr/local/etc/nextcloudpi-config.d/nc-automount.sh | cut -d'=' -f2 )"
echo "USB devices|$USBDEVS"
echo "datadir|$DATADIR$DIRINFO"
[[ "$DIRINFO" == "" ]] && {
echo "data in SD|$( [[ $( stat -fc%d / ) == $( stat -fc%d "$DATADIR" ) ]] && echo yes || echo no )"
echo "data filesystem|$( stat -fc%T $DATADIR )"
echo "data disk usage|$( df -h "$DATADIR" | tail -1 | awk '{ print $3"/"$2 }')"
}
echo "rootfs usage|$( df -h / | tail -1 | awk '{ print $3"/"$2 }')"

# Nextcloud
VERSION="$( sudo -u www-data /var/www/nextcloud/occ status | grep "version:" | awk '{ print $3 }' )"
if [[ "$VERSION" != "" ]]; then
echo "Nextcloud check|ok"
echo "Nextcloud version|$VERSION"
else
echo "Nextcloud check|error"
fi

# Services
echo "HTTPD service|$( pgrep -c apache2 &>/dev/null && echo up || echo down )"
echo "PHP service|$( pgrep -c php-fpm &>/dev/null && echo up || echo down )"
echo "MariaDB service|$( pgrep -c mysqld &>/dev/null && echo up || echo down )"
echo "Redis service|$( pgrep -c redis-server &>/dev/null && echo up || echo down )"
echo "Postfix service|$( postfix status &>/dev/null && echo up || echo down )"

# WAN
echo "internet check|$( ping -W 2 -w 1 -q github.com &>/dev/null && echo ok || echo no } )"

function is_port_open()
{
PORT=$1
wget -q http://canyouseeme.org --post-data \
"IP=$(wget -q ipinfo.io/ip -O -)&port=$PORT" \
-O - | grep -q "Connection refused" && { echo "closed"; return 1; }
echo "open"
}

echo "port check 80|$( is_port_open 80 )"
echo "port check 443|$( is_port_open 443 )"

# LAN
IFACE=$( ip r | grep "default via" | awk '{ print $5 }' )
GW=$( ip r | grep "default via" | awk '{ print $3 }' )
IP=$( ip a show dev "$IFACE" | grep global | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )

echo "IP|$IP"
echo "gateway|$GW"
echo "interface|$IFACE"

# Certificates
LEOUT="$( /etc/letsencrypt/letsencrypt-auto certificates 2>/dev/null )"
CERTS="$( echo -e "$LEOUT" | grep "Domains:" | awk '{ print $2 }' )"
CDUE="$( echo -e "$LEOUT" | grep "VALID:" | grep -oP "\d+ days" )"
[[ "$CERTS" == "" ]] && CERTS=none
[[ "$CDUE" == "" ]] && CDUE=none
echo "certificates|$CERTS"
echo "certs due|$CDUE"

RESOLV="$( ping -c 1 "$CERTS" | head -1 | grep -oP '\d{1,3}(.\d{1,3}){3}' )"
echo "NAT loopback|$( [[ "$RESOLV" == "$IP" ]] && echo yes || echo no )"

# Other
echo "uptime|$( uptime | cut -f1 -d',' | awk '{ $1=""; $2=""; print }' | tr -d " " )"

# License
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307 USA
86 changes: 86 additions & 0 deletions bin/ncp-report
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

# NextCloudPi diagnostics report
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
#
# Usage:
# sudo ncp-report
#
# More at https://ownyourbits.com
#

function open_summary()
{
echo "
<details>
<summary>$@</summary>
\`\`\`
"
}

function close_summary()
{
echo "
\`\`\`
</details>
"
}

[[ ${EUID} -ne 0 ]] && {
printf "Must be run as root. Try 'sudo $0'\n"
exit 1
}

echo "<--! Paste this in GitHub report -->"

##

open_summary "NextCloudPi diagnostics"
ncp-diag | column -t -s'|'
close_summary

##

open_summary "Nextcloud configuration"
sudo -u www-data /var/www/nextcloud/occ config:list system
close_summary

##

open_summary "HTTPd logs"
tail -20 /var/log/apache2/error.log
close_summary

##

open_summary "Database logs"
tail -20 /var/log/mysql/*.log
close_summary

##

DATADIR="$( grep datadirectory /var/www/nextcloud/config/config.php |
awk '{ print $3 }' | grep -oP "[^']*[^']" | head -1 )"

open_summary "Nextcloud logs"
tail -20 "$DATADIR"/nextcloud.log
close_summary

# License
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307 USA
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

[v0.35.1](https://github.com/nextcloud/nextcloudpi/commit/c3195c6) (2017-11-17) nc-datadir: make backup if non empty
[v0.36.0 ](https://github.com/nextcloud/nextcloudpi/commit/1b101b2) (2017-11-18) added ncp-diag and ncp-report

[v0.35.2 ](https://github.com/nextcloud/nextcloudpi/commit/f23f307) (2017-11-17) nextcloudpi-config: inform changelog

[v0.35.1 ](https://github.com/nextcloud/nextcloudpi/commit/61c5dc6) (2017-11-17) nc-datadir: make backup if non empty

[v0.35.0 ](https://github.com/nextcloud/nextcloudpi/commit/05dd8e3) (2017-11-17) added nc-passwd

Expand Down

0 comments on commit ede912f

Please sign in to comment.