Using #PowerShell to talk to #InfluxDB #InfluxDataPublished on 20 Nov 2017
Tags #PowerShell #Modules #InfluxDB
In my last post, I released several PowerShell modules to talk to several CI/CD tools. This includes InfluxDB a time-series database which is part of the TICK stack by InfluxData for storing and analyzing monitoring data.
Install-Module -Name Helpers, WebRequest, InfluxDb -Scope CurrentUser -AllowClobber
If you need to make this work through a proxy, tell
WebRequest to do so for you:
$ProxyPreference = 'Proxy' $ProxyServer = 'http://220.127.116.11:3128'
Before the cmdlets contained in the module can be used to talk to InfluxDB, the modules needs to know where the server lives and how to authenticate against it:
Set-InfluxDbServer -Server influxdb.mydomain.com -User myuser -Token mytoken
Let’s first take a look at the cmdlets contained in the module:
PS> Get-Command -Module InfluxDb CommandType Name Version Source ----------- ---- ------- ------ Function Add-InfluxDbPrivilege 0.5.14 InfluxDb Function Get-InfluxDbDatabase 0.5.14 InfluxDb Function Get-InfluxDbField 0.5.14 InfluxDb Function Get-InfluxDbMeasurement 0.5.14 InfluxDb Function Get-InfluxDbPrivilege 0.5.14 InfluxDb Function Get-InfluxDbUser 0.5.14 InfluxDb Function New-InfluxDbDatabase 0.5.14 InfluxDb Function New-InfluxDbUser 0.5.14 InfluxDb Function Remove-InfluxDbDatabase 0.5.14 InfluxDb Function Remove-InfluxDbPrivilege 0.5.14 InfluxDb Function Remove-InfluxDbUser 0.5.14 InfluxDb Function Set-InfluxDbServer 0.5.14 InfluxDb
By using the cmdlets show above, you can analyze the databases, measurements and fields as well as the users and their privileges. But they also help adding databases, users and privileges.
The following example creates a database as well as a new user with full access to it:
PS> New-InfluxDbDatabase -Database MyNewDb PS> New-InfluxDbUser -User MyNewUser -Password MyPassword PS> Add-InfluxDbPrivilege -Database MyNewDb -User MyNewUser -Privilege All
Although it is really nifty to create all this from the console instead of writing the low-level statements directly against InfluxDB, it still requires three cmdlets to be executes. When I create a new database in InfluxDB, I usually create two new dedicated users - a reader and a writer - to accompany the database. Therefore, I added the appropriate parameters to
New-InfluxDbDatabase to make this really easy:
New-InfluxDbDatabase -Database MySecondNewDb -ReaderUser MyDbReader -ReaderPassword MyReadPw -WriterUser MyDbWriter -WriterPassword MyWritePw
If you have feedback please let create an issue.