Resource report

Tell us your most wanted features from QNAP products.
Post Reply
themuscle
New here
Posts: 2
Joined: Sun Oct 26, 2014 4:52 am

Resource report

Post by themuscle »

For an IT admin or someone running a small business it would be invaluable to have the ability to schedule a simple report showing the utilisation of your hard disks.

Resource Monitor already has a great looking window called "Disk Usage" we just need the ability to e-mail this in HTML based on a schedule.

The e-mail would just list the raid or virtual disk and then show Total, used and free disk space.

For qnap units that have very high traffic on a daily basis this would be a great addition.

Regards, Mike
User avatar
pwilson
Guru
Posts: 22533
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: Resource report

Post by pwilson »

themuscle wrote:For an IT admin or someone running a small business it would be invaluable to have the ability to schedule a simple report showing the utilisation of your hard disks.

Resource Monitor already has a great looking window called "Disk Usage" we just need the ability to e-mail this in HTML based on a schedule.

The e-mail would just list the raid or virtual disk and then show Total, used and free disk space.

For qnap units that have very high traffic on a daily basis this would be a great addition.

Regards, Mike
Assuming that your SSMTP Server is properly configured, and you can successfully send test notification e-mails. The following script would do it for you.

(Note you will need to modify the SendTo, SendFrom, and (possibly Subject) variables at the top of the script

Code: Select all

#!/bin/sh
#
# nasnotify.sh - aka /share/homes/admin/bin/nasnotify.sh
# 
#  This script e-mails a report on the NAS / Drive Status to the designated recipient
#  See QNAP Forum article: http://forum.qnap.com/viewtopic.php?f=24&t=99093
# 
SendTo="me@somewhere.com"
SendFrom="TS-459@XXXXXX.myqnapcloud.com"
Subject="Resource Report from $(/bin/hostname)"
#
#
rm -f /tmp/nasreport.email
touch /tmp/nasreport.email
echo "From: ${SendFrom}"     >>/tmp/nasreport.email
echo "To: ${SendTo}"         >>/tmp/nasreport.email
echo "Subject: ${Subject}"   >>/tmp/nasreport.email
echo " "		     >>/tmp/nasreport.email


rm -f /tmp/nasreport
touch /tmp/nasreport
chmod +x /tmp/nasreport
cat <<EOF >>/tmp/nasreport
#!/bin/sh
#
# NAS Report by Patrick Wilson
# see: http://forum.qnap.com/viewtopic.php?f=185&t=82260#p366188
#
# 
echo "*********************"
echo "** QNAP NAS Report **"
echo "*********************"
echo " "
echo "NAS Model:      \$(getsysinfo model)"
echo "Firmware:       \$(getcfg system version) Build \$(getcfg system 'Build Number')"
echo "System Name:    \$(/bin/hostname)"
echo "Workgroup:      \$(getcfg system workgroup)"
echo "Base Directory: \$(dirname \$(getcfg -f /etc/config/smb.conf Public path))"
echo "NAS IP address: \$(ifconfig \$(getcfg network 'Default GW Device') | grep addr: | awk '{ print \$2 }' | cut -d: -f2)"
echo " " 
echo "Default Gateway Device: \$(getcfg network 'Default GW Device')" 
echo " "
ifconfig \$(getcfg network 'Default GW Device') | grep -v HWaddr
echo " "
echo -n "DNS Nameserver(s):" 
cat /etc/resolv.conf | grep nameserver | cut -d' ' -f2
echo " "
echo " "
echo "HDD Information:"
echo " "
if [ -x /sbin/hdparm ]; then
   for i in {a..d}; do echo -n /dev/sd\$i ; hdparm -i /dev/sd\$i | grep "Model"; done
else 
   echo "   /sbin/hdparm is not present" 
fi
echo " "
echo "Disk Space:"
echo " "
df -h | grep -v qpkg | grep -v grep
echo " "
echo "Mount Status:" 
echo " "
mount | grep -v qpkg
echo " " 
echo "RAID Status:" 
echo " " 
cat /proc/mdstat
echo " " 
#echo "QNAP Media Scanner / Transcoder processes running: "
#echo " " 
#/bin/ps | grep medialibrary | grep -v grep
#echo " " 
#echo -n "MediaLibrary Configuration file: " 
#ls -alF /etc/config/medialibrary.conf
#echo " " 
#echo "/etc/config/medialibrary.conf:"
#cat /etc/config/medialibrary.conf
echo " "
echo "Memory Information:" 
echo " "
cat /proc/meminfo | grep Mem
echo " "
echo "NASReport completed on \$(date +'%Y-%m-%d %T') ($0)" 
EOF
/tmp/nasreport >>/tmp/nasreport.email
cat /tmp/nasreport.email | sendmail -t 
rm -f /tmp/nasreport.email
echo "Done." 
#done



This isn't pretty, but it will get the job done without any MIME encoding, or HTML bloat. It's a simple text report, surely text is good enough for the e-mail message too to get the job done. Tested here. This script successfully delivered my NASReport output to my e-mail box. Simply save this script to somewhere on your NAS that will survive a reboot. (I created it at /share/homes/admin/bin/nasnotify.sh here)

If you save this script to the same location and make it executable, you can run if from the command line as often as you want.

Code: Select all

chmod +x /share/homes/admin/bin/nasnotify.sh


You can also make it run daily by adding it to the NAS Crontab file. If you wanted to run it at 3am every Sunday you can do this with the following commands:

Code: Select all

echo "0 3 * * 0 /share/homes/admin/bin/nasnotify.sh" >>/etc/config/crontab
#load Crontab changes...
crontab /etc/config/crontab
#restart Cron daemon to pickup the new item
/etc/init.d/crond.sh restart
#done
 

Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.
themuscle
New here
Posts: 2
Joined: Sun Oct 26, 2014 4:52 am

Re: Resource report

Post by themuscle »

This is great, I will give it a try over the weekend.
Thanks for the reply.

Regards, Michael
nsfw
Starting out
Posts: 25
Joined: Wed May 27, 2009 10:56 pm

Re: Resource report

Post by nsfw »

Thanks for this Patrick.
I realized what a mess crontab is in after installing notestation.
michael14094
New here
Posts: 4
Joined: Sun Feb 22, 2015 12:01 am

Re: Resource report

Post by michael14094 »

This does not work for me. I receive "SENDMAIL: 550 5.6.0 Invalid header found (see RFC2822 section 3.6) Done. I can send a test email from the GUI control panel just fine so it's definitely in the script.
User avatar
schumaku
Guru
Posts: 43578
Joined: Mon Jan 21, 2008 4:41 pm
Location: Kloten (Zurich), Switzerland -- Skype: schumaku
Contact:

Re: Resource report

Post by schumaku »

michael14094 wrote:This does not work for me. I receive "SENDMAIL: 550 5.6.0 Invalid header found (see RFC2822 section 3.6) Done. I can send a test email from the GUI control panel just fine so it's definitely in the script.
Unkless you have added some Mess-DOS CR/LF line terminators to the script ...

The key is that most SMTP handlers require a valid "From:" address - instead of the suggested ...

SendFrom="TS-459@XXXXXX.myqnapcloud.com"

...use your e-mail address configured for SMTP submission on the NAS.

It works:

===
Return-Path: <kurt.<<snip>>>
Received: from TVS-473 (<<snip>>. [<<snip>>])
by smtp.gmail.com with SMTPSA id <<snip>>.2.2016.11.19.12.44.21
for <kurt.<<snip>>>
(version=TLS1_2 cipher=AES128-SHA bits=128/128);
Sat, 19 Nov 2016 12:44:22 -0800 (PST)
Message-ID: <<<snip>>@mx.google.com>
Received: by TVS-473 (sSMTP sendmail emulation); Sat, 19 Nov 2016 21:41:23 +0100
Date: Sat, 19 Nov 2016 21:41:23 +0100
From: kurt.<<snip>>
To: kurt.<<snip>>
Subject: Resource Report from TVS-473

*********************
** QNAP NAS Report **
*********************

NAS Model: TVS-473
Firmware: 4.3.0 Build 20161107
System Name: TVS-473
...
michael14094
New here
Posts: 4
Joined: Sun Feb 22, 2015 12:01 am

Re: Resource report

Post by michael14094 »

I have done that, of course. I am using the exact same "from" and "to" addresses that I have setup in the gui. I can send test emails from the gui with no problem. I am using the smtp server from my isp which I use as a smtp relay server with all of my other devices perfectly fine. There is something in this script that the smtp server does not like.
User avatar
schumaku
Guru
Posts: 43578
Joined: Mon Jan 21, 2008 4:41 pm
Location: Kloten (Zurich), Switzerland -- Skype: schumaku
Contact:

Re: Resource report

Post by schumaku »

michael14094 wrote:There is something in this script that the smtp server does not like.
Strongly doubt...

Change the sendmail (ssmtp) options from -t to -v -t near to the end:

old:

Code: Select all

cat /tmp/nasreport.email | sendmail -t
new:

Code: Select all

cat /tmp/nasreport.email | sendmail -v -t


..and now run the script again. Post the output (remove any sensitive AUTH data like usernames, paswords, or XOAUTH2 code. I'm glad to have an eye on your output.

Note: As per RFC2822 section 3.6 only two fields (plus the receiver address as a "To" obviously) are mandatory - marked bold in this example:

[<-] 220 smtp.gmail.com ESMTP g10sm19946697wjw.18 - gsmtp
[->] HELO TVS-473
[<-] 250 smtp.gmail.com at your service
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 400 100 294 100 106 580 209 --:--:-- --:--:-- --:--:-- 601
[->] AUTH XOAUTH2 <<SNIP>>==
[<-] 235 2.7.0 Accepted
[->] MAIL FROM:<kurt.<<SNIP>>>
[<-] 250 2.1.0 OK g10sm19946697wjw.18 - gsmtp
[->] RCPT TO:<kurt.<<SNIP>>>
[<-] 250 2.1.5 OK g10sm19946697wjw.18 - gsmtp
[->] DATA
[<-] 354 Go ahead g10sm19946697wjw.18 - gsmtp
[->] Received: by TVS-473 (sSMTP sendmail emulation); Sun, 20 Nov 2016 16:51:47 +0100
[->] Date: Sun, 20 Nov 2016 16:51:47 +0100
[->] From: kurt.<<SNIP>>
[->] To: kurt.<<SNIP>>
[->] Subject: Resource Report from TVS-473

[->] *********************
[->] ** QNAP NAS Report **
[->] *********************

[->] NAS Model: TVS-473
[->] Firmware: 4.3.0 Build 20161107
[->] System Name: TVS-473
...
Post Reply

Return to “Features Wanted”