Skip to content

Commit

Permalink
Tune scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
François ROLAND committed Jul 17, 2018
1 parent a2f7cca commit 9fcc834
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
*.iml
*.log
14 changes: 14 additions & 0 deletions create-training-user-set.PS1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if ($args.Count -ne 1)
{
Write-Host 'Wrong argument count'
Write-Host 'usage: .\create-training-user-set.PS1 <gateway_ip>'
exit
}

$Gateway = $args[0]
$UserCount = 12
Write-Host "Creating $($UserCount) users on IoT-Lab gateway $($Gateway)"

for ($i = 1; $i -lt $($UserCount + 1); $i++) {
.\create-user.PS1 $($Gateway) "training$($i)"
}
29 changes: 17 additions & 12 deletions create-user.PS1
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,27 @@ Write-Host "Creating user $($NewUser) on IoT-Lab gateway $($Gateway)"

Write-Host ' - InfluxDB'
Write-Host ''
http --form POST "$($Gateway):8086/query" q='CREATE DATABASE "'$($NewUser)'"'
http "$($Gateway):8086/query" q=='SHOW DATABASES'
http -o remove-user.log --form POST "$($Gateway):8086/query" q='CREATE DATABASE "'$($NewUser)'"'

Write-Host ' - Grafana'
Write-Host ''
Write-Host ' New Organization'
http -a admin:admin POST "$($Gateway)/grafana/api/orgs" "name=$($NewUser)"
$OrganizationId = $(http -a admin:admin -b GET "$($Gateway)/grafana/api/orgs/name/$($NewUser)" | ConvertFrom-Json).id
Write-Host ' New organisation'
http -o remove-user.log -a admin:admin POST "$($Gateway)/grafana/api/orgs" "name=$($NewUser)"
$organisationId = $(http -a admin:admin -b GET "$($Gateway)/grafana/api/orgs/name/$($NewUser)" | ConvertFrom-Json).id

http -a admin:admin POST "$($Gateway)/grafana/api/user/using/$($OrganizationId)"
http -o remove-user.log -a admin:admin POST "$($Gateway)/grafana/api/user/using/$($organisationId)"

#Write-Host ' New User'
#http -a admin:admin POST "$($Gateway)/grafana/api/admin/users" "name=$($NewUser)" "email=$($NewUser)@iotlab-gw.io" "login=$($NewUser)" "password=$($NewUser)" "orgId:=$($OrganizationId)"
Write-Host ' Add User to Organization'
http -a admin:admin POST "$($Gateway)/grafana/api/org/users" "loginOrEmail=$($NewUser)" "role=Admin"
Write-Host ' New User'
http -o remove-user.log -a admin:admin POST "$($Gateway)/grafana/api/admin/users" "name=$($NewUser)" "email=$($NewUser)@iotlab-gw.io" "login=$($NewUser)" "password=$($NewUser)"
$UserId = $(http -a admin:admin GET "$($Gateway)/grafana/api/users/lookup" "loginOrEmail==$($NewUser)" | ConvertFrom-Json).id
Write-Host ' Add User to organisation'
http -o remove-user.log -a admin:admin POST "$($Gateway)/grafana/api/org/users" "loginOrEmail=$($NewUser)" "role=Admin"
Write-Host ' Remove User from default organisation'
http -o remove-user.log -a admin:admin DELETE "$($Gateway)/grafana/api/orgs/1/users/$($UserId)"
Write-Host ' New Datasource'
http -a admin:admin POST "$($Gateway)/grafana/api/datasources" "name=$($NewUser)" "type=influxdb" "url=http://influxdb:8086" "database=$($NewUser)" "isDefault:=true" "access=proxy" "typeLogoUrl=public/app/plugins/datasource/influxdb/img/influxdb_logo.svg"
http -o remove-user.log -a admin:admin POST "$($Gateway)/grafana/api/datasources" "name=$($NewUser)" "type=influxdb" "url=http://influxdb:8086" "database=$($NewUser)" "isDefault:=true" "access=proxy" "typeLogoUrl=public/app/plugins/datasource/influxdb/img/influxdb_logo.svg"

http -a admin:admin POST "$($Gateway)/grafana/api/user/using/1"
http -o remove-user.log -a admin:admin POST "$($Gateway)/grafana/api/user/using/1"

Write-Host "User $($NewUser) created"
Write-Host ''
14 changes: 14 additions & 0 deletions remove-training-user-set.PS1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if ($args.Count -ne 1)
{
Write-Host 'Wrong argument count'
Write-Host 'usage: .\cleanup-training-user-set.PS1 <gateway_ip>'
exit
}

$Gateway = $args[0]
$UserCount = 12
Write-Host "Cleaning up $($UserCount) users on IoT-Lab gateway $($Gateway)"

for ($i = 1; $i -lt $($UserCount + 1); $i++) {
.\remove-user.PS1 $($Gateway) "training$($i)"
}
29 changes: 29 additions & 0 deletions remove-user.PS1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
if ($args.Count -ne 2)
{
Write-Host 'Wrong argument count'
Write-Host 'usage: .\remove-user.PS1 <gateway_ip> <new_username>'
exit
}

$Gateway = $args[0]
$UserToDelete = $args[1]
Write-Host "Removing user $($UserToDelete) from IoT-Lab gateway $($Gateway)"

Write-Host ' - Grafana'

http -o remove-user.log -a admin:admin POST "$($Gateway)/grafana/api/user/using/1"

Write-Host ' Remove User'
$UserId = $(http -a admin:admin GET "$($Gateway)/grafana/api/users/lookup" "loginOrEmail==$($UserToDelete)" | ConvertFrom-Json).id
http -o remove-user.log -a admin:admin DELETE "$($Gateway)/grafana/api/admin/users/$($UserId)"
Write-Host ' Remove organisation'
$OrganisationId = $(http -a admin:admin -b GET "$($Gateway)/grafana/api/orgs/name/$($UserToDelete)" | ConvertFrom-Json).id
http -o remove-user.log -a admin:admin DELETE "$($Gateway)/grafana/api/orgs/$($OrganisationId)" "name=$($UserToDelete)"

Write-Host ''
Write-Host ' - InfluxDB'
http -o remove-user.log --form POST "$($Gateway):8086/query" q='DROP DATABASE "'$($UserToDelete)'"'

Write-Host ''
Write-Host "User $($UserToDelete) removed"
Write-Host ''

0 comments on commit 9fcc834

Please sign in to comment.