Code Monkey home page Code Monkey logo

itop-jb-powershell's Introduction

PSM1 iTop module for PowerShell

Copyright (C) 2019-2021 Jeffrey Bostoen

License Donate ๐Ÿป โ˜•

Need assistance with iTop or one of its extensions?
Need custom development?
Please get in touch to discuss the terms: [email protected] / https://jeffreybostoen.be

What?

A PowerShell module. Note: this is my very first PowerShell module ever.

Written to automate some tasks which are repeated a lot in development and production environments.

iTop API (REST/JSON) functions This also inherits the limitations present in the iTop API, although there are some work-arounds available too. The most important limitation is that with each HTTP request, only one object can be created, modified or deleted.

  • Get-iTopObject: get zero, one or more iTop objects (core/get)
  • New-iTopObject: create 1 iTop object (core/create)
  • Remove-iTopObject: delete iTop object(s) (core/delete)
  • Set-iTopObject: update iTop object(s) (core/update)

Miscellaneous

  • Install-iTopUnattended: performs an unattended (automatic) (re)installation of iTop.
  • Get-iTopClass: gets overview of each class, including parent and module where it's defined or changed
  • Get-iTopCommand: shows all iTop commands in this PS1 module.
  • Get-iTopEnvironment: set settings of an iTop environment
  • Invoke-iTopRestMethod: invokes POST request
  • New-iTopExtension: creates new extension from template
  • Remove-iTopLanguage: removes all unnecessary language files
  • Rename-iTopExtension: renames an extension. Renames folder, renames default files, replaces extension name in those files...
  • Set-iTopConfigWritable: makes or keeps (every 5 seconds) configuration file writable
  • Set-iTopEnvironment: set settings of an iTop environment
  • Set-iTopExtensionReleaseInfo: sets iTop extension release info (in "extensions" folder defined in the environment)
  • Start-iTopCron: starts iTop cron jobs

Installing

Hint: you can make sure this module is always loaded by default.

  • Enter $env:PSModulePath to see from which directories PowerShell tries to load modules.
  • Unzip the .psm1 and .psd files in this folder.
  • Open a new PowerShell console window.

Configuration example

"default" is the name of the default environment and should always be included. You can add more environments by adding an '.json' file in %UserProfile%\Documents\WindowsPowerShell\Modules\iTop\environments

API settings are useful in all cases. All other settings are primarily when you have iTop installed on the same machine as where you are running the PowerShell module on.

Variables: any key you define here, can be used as a variable (%name%) in the other parts of the configuration. Strings only for now.

{

	"Variables": {
		"Environment": "production",
	},
	
	"API": {
		"Url":  "http://127.0.0.1/itop/web/webservices/rest.php?login_mode=url",
		"Version":  "1.3",
		"Password":  "admin",
		"Output_Fields":  "*",
		"User":  "admin"
	},
	
	"App":  {
		"Path":  "C:\\xampp\\htdocs\\iTop\\web", 
		"ConfigFile":  "C:\\xampp\\htdocs\\iTop\\web\\conf\\production\\config-itop.php", 
		
		
		"UnattendedInstall": {
			"Script":  "C:\\xampp\\htdocs\\iTop\\web\\toolkit\\unattended_install.php", 
			"XML":  "C:\\xampp\\htdocs\\iTop\\web\\toolkit\\unattended_install.xml",
			"CleanXML":  "C:\\xampp\\htdocs\\iTop\\web\\toolkit\\unattended_install_clean.xml",
		},
		 
		"Languages": [
			"en",
			"nl"
		] 
	},
	
	"Extensions": {
	   "Path":  "C:\\xampp\\htdocs\\iTop\\web\\extensions", 
	   "Url":  "https://jeffreybostoen.be",
	   "VersionMin":  "2.7.0", 
	   "VersionDataModel":  "1.6", 
	   "Author":  "Jeffrey Bostoen", 
	   "Company":  "", 
	   "VersionDescription":  "" 
	},
	
	"Cron": {
		"User": "admin",
		"Password": "admin"
	}
	
}

Basic examples

You can execute for example Get-Help Get-iTopobject to get a full list and explanation of each parameter.

Mind that the structure is based on iTop's REST/JSON API.

Retrieving user requests of a certain person (with ID 1).

$tickets = Get-iTopObject -env "default" -key "SELECT UserRequest WHERE caller = 1"

Creating a new organization. This will give you access to the ID (key) created for this organization.

$ClientOrg = New-iTopObject -Environment "default" -Class "Organization" -Fields @{
	"name"="Demo Portal Org #1";
	"deliverymodel_id"=$DeliveryModel.key;
}

# Print ID of the newly created object
$ClientOrg.key

# Print fields
$ClientOrg.fields

Deleting an organization.

Remove-iTopObject -env "default" -key "SELECT Organization WHERE id = 1"

Updating an organization.

Set-iTopObject -env "default" -key "SELECT Organization WHERE id = 1" -Fields @{
	"name"="Demo 2"
}

Mind that by default, iTop will currently not allow you to update/delete multiple objects at once.
There must be one HTTP request per update/delete. To facilitate this, a -Batch:$true parameter exists.

Updating an organization for multiple persons.

Set-iTopObject -env "default" -key "SELECT Person WHERE org_id = 999" -Batch:$true -Fields @{
	"org_id"=1000
}

Upgrade notes

To version 2021-07-08 and higher:
Adjust URL to contain login_mode parameter to URL in configurations. Currently supported values are 'basic' and 'url'.

To version 2020-11-09 and higher:

$global:iTopEnvironments is no longer available.

Settings are now available through Get-iTopEnvironment and Set-iTopEnvironment

To version 2020-04-02 and higher:
If you used the functions from previous versions of this module, it might be necessary to make some changes.
First of all: multiple environments are now supported (for instance: development and production).
There's now one .JSON file for each iTop environment. The default environment is named "default.json".

Furthermore, Remove-iTopLanguages is now named Remove-iTopLanguage for consistency reasons.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.