Advertisement
AquaBlast

Untitled

Aug 21st, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.56 KB | None | 0 0
  1. #!/bin/bash -x
  2.  
  3. ### MoveSCU Verbose Parser for Zabbix Trapper Items
  4.  
  5. myAET="ZABBIX"
  6. callAET=$1
  7. pacsIP=$2
  8. pacsPort=$3
  9. query=$4
  10.  
  11. moveQueryVerbose="/etc/zabbix/scripts/moveQueryVerbose"
  12. moveQueryStatus="/etc/zabbix/scripts/moveQueryStatus"
  13. moveQueryDuration="/etc/zabbix/scripts/moveQueryDuration"
  14. movescu=$( which movescu )
  15. agentConfig="/etc/zabbix/zabbix_agentd.conf"
  16. zServer="`ifconfig eth0 | grep 'inet addr:' | sed -r 's/^.*inet\saddr\://;s/\s{2}Bcast.*$//'`"
  17. port="10051"
  18. agentHost=$( cat /etc/hostname )
  19. zSend=$( which zabbix_sender )
  20.  
  21. db='pacs_db_name'
  22. user='zabbix_user'
  23. pass='zabbix_user_pass'
  24.  
  25. queryRetrieve="QueryRetrieveLevel=SERIES"
  26. sIUID="SeriesInstanceUID=$seriesIUID"
  27.  
  28. moveQueryStatusMethod() {
  29.     mysqlQuery="select series_iuid from pacsdb.series where series_no='101' order by study_fk desc limit 1;"
  30.     seriesIUID=$( echo $mysqlQuery | mysql -N -h $pacsIP -u $user --password="$pass" --connect_timeout=10 $db )
  31.     if [[ -z $seriesIUID ]] ; then
  32.         mysqlQuery="select series_iuid from pacsdb.series where series_no='1' order by study_fk desc limit 1;"
  33.         seriesIUID=$( echo $mysqlQuery | mysql -N -h $pacsIP -u $user --password="$pass" $db )
  34.         seriesNum="SeriesNumber=1"
  35.     fi
  36.  
  37.     queryRetrieve="QueryRetrieveLevel=SERIES"
  38.     sIUID="SeriesInstanceUID=$seriesIUID"
  39.  
  40.     start=$( date +%s%N | cut -b1-13 )
  41.     $movescu -S -k $queryRetrieve -k $sIUID -aet $myAET -aec $callAET -aem $myAET -v -to 7 $pacsIP $pacsPort 2>$moveQueryVerbose
  42.     end=$( date +%s%N | cut -b1-13 )
  43.     moveDuration=$(( $end - $start ))
  44.     echo $moveDuration > $moveQueryDuration
  45.     while read line ; do
  46.         moveStatus=$( echo $line | grep Success )
  47.         if [[ -z $moveStatus ]] ; then
  48.             moveSeriesStatus=0
  49.             continue
  50.         else
  51.             moveStatus=$( echo $line | grep -oP '(?<=0x0000\:\s)(\w+)(?=$)' )
  52.             if [[ $moveStatus = "Success" ]] ; then
  53.                 moveSeriesStatus=1
  54.             fi
  55.             break
  56.         fi
  57.     done < $moveQueryVerbose
  58.  
  59.     if [[ $moveSeriesStatus -eq 0 ]] ; then
  60.         echo 0 > $moveQueryDuration
  61.     fi
  62.  
  63.     $zSend -c $agentConfig -z $zServer -p $port -s $agentHost -k movescu[$callAET,$pacsIP,$pacsPort,status] -o $moveSeriesStatus
  64.     rm $moveQueryVerbose
  65.     exit 0
  66. }
  67.  
  68. moveQueryDurationMethod() {
  69.     $zSend -c $agentConfig -z $zServer -p $port -s $agentHost -k movescu[$callAET,$pacsIP,$pacsPort,duration] -o $( cat $moveQueryDuration )
  70.     rm $moveQueryDuration
  71.     exit 0
  72. }
  73.  
  74. if [[ $query = "status" ]] ; then
  75.     moveQueryStatusMethod
  76. elif [[ $query = "duration" ]] ; then
  77.     moveQueryDurationMethod
  78. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement