Using Curl to Access Spiceworks
-
There are times that it might be beneficial to access Spiceworks via a command line, scriptable tool, such as cURL or wget. Since Spiceworks uses a complex, non-standard HTML login mechanism, this can be a little bit of a pain. But there is a simple mechanism for working around this using a Google Chrome plugin.
Before we get started, we need to install the Google Chrome plugin Cookie Exporter. Once that is installed, just log into the Spiceworks Community and use the tool to view your community cookie. Then just copy and paste that cookie data into a text file, for this example I will just call it cookie.txt to make things easy. You can name it anything you want and adjust accordingly. You can use Google Chrome anywhere for this, it could be done from the Linux machine that we are scripting or from a different Windows machine, does not matter.
If we put the cookie.txt file into the same directory from which we are working, we can now use wget to easily access a page in Spiceworks. Let’s try an example:
wget -x –load-cookies ./cookies.txt https://community.spiceworks.com/topic/429683-what-happens-when-the-180-day-evaluation-period-expires
Or we can do the same thing without using the full link and only useing the RESTful portion of it if this makes it more convenient (likely if we are doing any sort of automation.)
wget -x –load-cookies ./cookies.txt https://community.spiceworks.com/topic/429683
Both approaches work just fine. At this point you should have a local copy of that particular page. Not necessarily what we want, but this is a basic starting point. Now we will take this approach and apply it to cURL. For the purposes of showing some power in this approach, instead of a posting page I’ll use my own page as an example of how we can pull some statistics out of the system:
curl -b ./cookies.txt http://community.spiceworks.com/people/scottalanmiller/activity
Now we have a text stream of my activity report. A great starting point. But we get some cURL information as well via the error channel, so we should strip that out.
curl -b ./cookies.txt http://community.spiceworks.com/people/scottalanmiller/activity 2>/dev/null
Now we have something clean with which to work, just the HTML of the page itself. Let’s assume we want to pull out my current point data. This is easy enough to do with a quick grep for “Points”. And a few cuts will allow us to quickly strip away the superfluous HTML formatting leaving just the Points field.
curl -b ./cookies.txt http://community.spiceworks.com/people/scottalanmiller/activity 2>/dev/null | grep Points |cut -d”>” -f3 | cut -d”<” -f1
This is great, now we can simply query Spiceworks for Point or other data. Obviously this is just the starting point, there is extensive automation opportunities that can be done with additional scripting. But this is enough to explain how we can access Spiceworks data with Linux, BASH and cURL.
Originally posted on scottalanmiller.com on 11th January 2014