# Script for setting path for plugin testing

**URL:** <https://discourse.sensu.io/t/script-for-setting-path-for-plugin-testing/1269>\
**Category:** Sensu Plugins\
**Created:** [July 18, 2019, 6:34pm UTC](https://discourse.sensu.io/t/script-for-setting-path-for-plugin-testing/1269 "2019-07-18T18:34:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjthespian](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/sjthespian/32/152_2.png) [@sjthespian](https://discourse.sensu.io/u/sjthespian)\
**Post date:** [July 18, 2019, 6:34pm UTC](https://discourse.sensu.io/t/script-for-setting-path-for-plugin-testing/1269/1 "2019-07-18T18:34:12Z")

</div>

I have been going slightly nuts setting and resetting my path for plugin asset testing, so I threw together this quick script. I’m not sure if it will be of use to anyone else, but I threw it out here just in case. I have only used this on Ubuntu, you may need to change the path in the script for others OSs.

I typically use it by logging in as the sensu user and running something like (in bash):  
`eval sensu-setassetpath sensu-ruby-runtime sensu-plugins-http`  
That will set my PATH and LD\_LIBRARY\_PATH to include those two assets, then I can run commands like:  
`check-http.rb -a MyStrongPassword -U MyUser -u http://www.example.com/ -r`  
and try to figure out why they the plugin isn’t returning what I want it to.

```auto
#!/bin/bash
#
# Update path and library path for a particular plugin asset
#

CACHEDIR="/var/cache/sensu/sensu-agent"

usage() {
  if [-n "$1"]; then
    echo $*
  fi
  echo "usage: eval \"\$($0 asset)\""
  exit 1
}

# If no plugin specified, output list and usage message
if [-z "$1"]; then
  sensuctl asset list | awk '{print $1}'
  usage "You must specify one of the above assets"
fi

newpath=""
newlibpath=""
for i in $*; do
  sha=$(sensuctl asset info $i --format json | jq -r .sha512)
  if [-d ${CACHEDIR}/${sha}/bin]; then
    if [-z "$newpath"]; then
      newpath=${CACHEDIR}/${sha}/bin
    else
      newpath=${newpath}:${CACHEDIR}/${sha}/bin
    fi
  fi
  if [-d ${CACHEDIR}/${sha}/lib]; then
    if [-z "$newlibpath"]; then
      newlibpath=${CACHEDIR}/${sha}/lib
    else
      newlibpath=${newlibpath}:${CACHEDIR}/${sha}/lib
    fi
  fi
done

echo "export PATH=${newpath}:${PATH}"
echo "export LD_LIBRARY_PATH=${newlibpath}:${LD_LIBRARY_PATH}"

```

---

<div class="post-metadata">

**Author:** ![calebhailey](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/calebhailey/32/46_2.png) [@calebhailey](https://discourse.sensu.io/u/calebhailey)\
**Post date:** [July 18, 2019, 9:33pm UTC](https://discourse.sensu.io/t/script-for-setting-path-for-plugin-testing/1269/2 "2019-07-18T21:33:10Z")

</div>

Nice! Thanks for sharing. Also fully noted that a first-class utility or test harness would be helpful. I think we have a GitHub issue floating around somewhere for this, but I’d welcome a new issue that captures your use case - especially since you’ve spent some time prototyping a workaround.

Thanks again!

---

<div class="post-metadata">

**Author:** ![ceda](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/ceda/32/217_2.png) [@ceda](https://discourse.sensu.io/u/ceda)\
**Post date:** [November 16, 2019, 2:09pm UTC](https://discourse.sensu.io/t/script-for-setting-path-for-plugin-testing/1269/3 "2019-11-16T14:09:19Z")

</div>

Thanks a bunch. I noted that this must be run as a user that has read access to those directories. 🙂
