Skip to content

Instantly share code, notes, and snippets.

@rkaldung
Last active August 25, 2021 11:21
Show Gist options
  • Select an option

  • Save rkaldung/1ae7b8e2fe73dfdd7ee218f6867b557b to your computer and use it in GitHub Desktop.

Select an option

Save rkaldung/1ae7b8e2fe73dfdd7ee218f6867b557b to your computer and use it in GitHub Desktop.

Revisions

  1. rkaldung revised this gist Aug 25, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    ## Requirements
    - ((OTRS)) Community Edition 6
    - Znuny LTS or ((OTRS)) Community Edition 6
    - Add-ons
    - GeneralCatalog
    - ITSMCore
  2. rkaldung revised this gist Dec 28, 2020. 1 changed file with 172 additions and 0 deletions.
    172 changes: 172 additions & 0 deletions CI Definition Computer
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,172 @@
    ---
    - Key: Vendor
    Name: Vendor
    Searchable: 1
    Input:
    Type: Text
    Size: 50
    MaxLength: 50
    # Example for CI attribute syntax check for text and textarea fields
    #RegEx: ^ABC.*
    #RegExErrorMessage: Value must start with ABC!

    - Key: Model
    Name: Model
    Searchable: 1
    Input:
    Type: Text
    Size: 50
    MaxLength: 50

    - Key: Description
    Name: Description
    Searchable: 1
    Input:
    Type: TextArea

    - Key: Type
    Name: Type
    Searchable: 1
    Input:
    Type: GeneralCatalog
    Class: ITSM::ConfigItem::Computer::Type
    Translation: 1

    - Key: CustomerID
    Name: Customer Company
    Searchable: 1
    Input:
    Type: CustomerCompany

    - Key: Owner
    Name: Owner
    Searchable: 1
    Input:
    Type: Customer

    - Key: SerialNumber
    Name: Serial Number
    Searchable: 1
    Input:
    Type: Text
    Size: 50
    MaxLength: 100

    - Key: OperatingSystem
    Name: Operating System
    Input:
    Type: Text
    Size: 50
    MaxLength: 100

    - Key: CPU
    Name: CPU
    Input:
    Type: Text
    Size: 50
    MaxLength: 100
    CountMax: 16

    - Key: Ram
    Name: Ram
    Input:
    Type: Text
    Size: 50
    MaxLength: 100
    CountMax: 10

    - Key: HardDisk
    Name: Hard Disk
    Input:
    Type: Text
    Size: 50
    MaxLength: 100
    CountMax: 10
    Sub:
    - Key: Capacity
    Name: Capacity
    Input:
    Type: Text
    Size: 20
    MaxLength: 10

    - Key: FQDN
    Name: FQDN
    Searchable: 1
    Input:
    Type: Text
    Size: 50
    MaxLength: 100

    - Key: NIC
    Name: Network Adapter
    Input:
    Type: Text
    Size: 50
    MaxLength: 100
    Required: 1
    CountMin: 0
    CountMax: 10
    CountDefault: 0
    Sub:
    - Key: IPoverDHCP
    Name: IP over DHCP
    Input:
    Type: GeneralCatalog
    Class: ITSM::ConfigItem::YesNo
    Translation: 1
    Required: 0
    - Key: IPAddress
    Name: IP Address
    Searchable: 1
    Input:
    Type: Text
    Size: 40
    MaxLength: 40
    Required: 0
    CountMin: 0
    CountMax: 20
    CountDefault: 0

    - Key: GraphicAdapter
    Name: Graphic Adapter
    Input:
    Type: Text
    Size: 50
    MaxLength: 100

    - Key: OtherEquipment
    Name: Other Equipment
    Input:
    Type: TextArea
    Required: 1
    CountMin: 0
    CountDefault: 0

    - Key: WarrantyExpirationDate
    Name: Warranty Expiration Date
    Searchable: 1
    Input:
    Type: Date
    YearPeriodPast: 20
    YearPeriodFuture: 10

    - Key: InstallDate
    Name: Install Date
    Searchable: 1
    Input:
    Type: Date
    Required: 1
    YearPeriodPast: 20
    YearPeriodFuture: 10
    CountMin: 0
    CountDefault: 0

    - Key: Note
    Name: Note
    Searchable: 1
    Input:
    Type: TextArea
    Required: 1
    CountMin: 0
    CountDefault: 0
  3. rkaldung revised this gist Dec 28, 2020. 1 changed file with 95 additions and 0 deletions.
    95 changes: 95 additions & 0 deletions expires.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,95 @@
    $user = "xx"
    $pass = "xx"
    $uri = "https://xx.yy.zz.com/otrs/nph-genericinterface.pl/Webservice"

    $headers = @{}
    $headers.Add("Accept", "application/json")
    $headers.Add("Content-Type", "application/json")

    # Get Session
    $LoginDetails = @{
    UserLogin = $user
    Password = $pass
    }
    $json = $LoginDetails | ConvertTo-Json
    $response = Invoke-RestMethod -Method Post -Headers $Headers -ContentType 'application/json' -Uri "$uri/CMDB/Session" -Body $json
    if ( $response.Error ) {
    $code = $response.Error.ErrorCode
    $message = $response.Error.ErrorMessage
    Write-Host "Creating session failed (${code}: $message)"
    exit 1

    }
    $SessionID = $response.SessionID

    $Today = Get-Date -Format "yyyy-MM-dd"

    # Which classes to check
    $Classes = @("Computer")
    foreach ( $Class in $Classes ) {
    Write-Host Search for ConfigItems of class $Class

    # Search ConfigItems
    # Parameter see https://github.com/OTRS/ITSMConfigurationManagement/blob/rel-6_0/Kernel/GenericInterface/Operation/ConfigItem/ConfigItemSearch.pm#L125
    $SearchParameter = @{
    SessionID = $SessionID
    ConfigItem = @{
    Class = $Class
    Limit = 10000
    DeplStates = @(
    "Production"
    )
    }
    }
    $json = $SearchParameter | ConvertTo-Json -Depth 3
    $response = Invoke-RestMethod -Method Post -Headers $Headers -Uri "$uri/CMDB/ConfigItem" -Body $json
    if ( $response.Error ) {
    $code = $response.Error.ErrorCode
    $message = $response.Error.ErrorMessage
    Write-Host "Search for ConfigItems failed (${code}: $message)"
    exit 1
    }

    # next iteration of no CIs found
    if ( !$response.ConfigItemIDs ) {
    continue
    }

    $ConfigItemIDs = $response.ConfigItemIDs
    foreach ( $ConfigItemID in $ConfigItemIDs) {
    Write-Host Fetching ConfigItem with ID $ConfigItemID
    $response = Invoke-RestMethod -Method Get -Headers $Headers -Uri "$uri/CMDB/ConfigItem/${ConfigItemID}?SessionID=${SessionID}"
    if ( $response.Error ) {
    $code = $response.Error.ErrorCode
    $message = $response.Error.ErrorMessage
    Write-Host "Get ConfigItems with id $ConfigItemID failed (${code}: $message)"
    continue
    }
    $ConfigItem = $response.ConfigItem
    Write-Host -NoNewLine CI $ConfigItem.Number ($ConfigItem.Name) "is "
    if ( $ConfigItem.CIXMLData.WarrantyExpirationDate -le $Today ) {
    Write-Host expired
    $UpdatedCI = @{
    SessionID = $SessionID
    ConfigItemID = $ConfigItemID
    ConfigItem = @{
    Class = $Class
    Name = $ConfigItem.Name
    DeplState = "Expired"
    InciState = $ConfigItem.InciState
    CIXMLData = $ConfigItem.CIXMLData
    }
    }
    $json = $UpdatedCI | ConvertTo-Json -Depth 5
    $response = Invoke-RestMethod -Method Post -Headers $Headers -Uri "$uri/CMDB/ConfigItem/${ConfigItemID}" -Body $json
    if ( $response.Error ) {
    $code = $response.Error.ErrorCode
    $message = $response.Error.ErrorMessage
    Write-Host "Seettig ConfigItems with id $ConfigItemID to eexpired failed (${code}: $message)"
    continue
    }
    } else {
    Write-Host not expired
    }
    }
    }
  4. rkaldung revised this gist Dec 28, 2020. 2 changed files with 48 additions and 1 deletion.
    46 changes: 46 additions & 0 deletions CMDB.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    ---
    Debugger:
    DebugThreshold: debug
    TestMode: '0'
    Description: ''
    FrameworkVersion: 6.0.27
    Provider:
    Operation:
    ConfigItemGet:
    Description: ''
    IncludeTicketData: '0'
    Type: ConfigItem::ConfigItemGet
    ConfigItemSearch:
    Description: ''
    IncludeTicketData: '0'
    Type: ConfigItem::ConfigItemSearch
    SessionCreate:
    Description: ''
    IncludeTicketData: '0'
    Type: Session::SessionCreate
    Transport:
    Config:
    AdditionalHeaders: ~
    KeepAlive: ''
    MaxLength: '10000000'
    RouteOperationMapping:
    ConfigItemGet:
    ParserBackend: JSON
    RequestMethod:
    - GET
    Route: /ConfigItem/:ConfigItemID
    ConfigItemSearch:
    ParserBackend: JSON
    RequestMethod:
    - POST
    Route: /ConfigItem
    SessionCreate:
    ParserBackend: JSON
    RequestMethod:
    - POST
    Route: /Session
    Type: HTTP::REST
    RemoteSystem: ''
    Requester:
    Transport:
    Type: ''
    3 changes: 2 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,5 @@
    - ITSMCore
    - ITSMConfigurationManagement


    ## Webservice
    Add a new webservice by uploading the file CMDB.yml as a new webservice configuration.
  5. rkaldung revised this gist Dec 28, 2020. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,8 @@
    ## Test
    ## Requirements
    - ((OTRS)) Community Edition 6
    - Add-ons
    - GeneralCatalog
    - ITSMCore
    - ITSMConfigurationManagement


  6. rkaldung created this gist Dec 28, 2020.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ## Test