Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create/update CMDB objects and their category entries #13

Closed
bheisig opened this issue Sep 25, 2018 · 1 comment
Closed

Create/update CMDB objects and their category entries #13

bheisig opened this issue Sep 25, 2018 · 1 comment

Comments

@bheisig
Copy link
Owner

bheisig commented Sep 25, 2018

Create a new object

idoitcli set server/mylittleserver

Create/update attributes in a single-value category

idoitcli set server/mylittleserver/model --manufacturer A --title 123
idoitcli set server/mylittleserver/location --he 11

Update attributes in a multi-value category

idoitcli set server/mylittleserver/hostaddress/1 --ipv4address 192.168.42.23

Interactive mode

First, collect data:

$ idoitcli set
Create new object
Type? server
Title? mylittleserver
Add more attributes [y/N]? y
[Model] Manufacturer? A
[Model] Model? 123
[Hostaddress] Hostname? mylittleserver
[Location] Location? rackXY
[…]
  • Add more attributes will be asked if template is available (see below)
  • Category/attribute names will be printed human-readable
  • Print summary before pushing data to i-doit

Templates

Based on object type specific templates in configuration file create/update objects and their attributes.

{
    "templates":
        "server": [
            {
                "category": "C__CATG__MODEL",
                "attribute": "manufacturer"
            },
            {
                "category": "C__CATG__MODEL",
                "attribute": "title"
            },
            {
                "category": "C__CATG__IP",
                "attribute": "hostname"
            },
            {
                "category": "C__CATG__LOCATION",
                "attribute": "location"
            }
        ]
}
  • Order matters

Common aspects

  • It's irrelevant if a new data set will be created or an existing one will be updated. Instead, print to STDOUT what happened exactly.
@bheisig
Copy link
Owner Author

bheisig commented Nov 29, 2018

Feature has been implemented. As you can see the usage is slightly different as specified (IMHO it's even better):

$ idoitcli save --help
Create/update CMDB objects and their category entries

USAGE
    $ idoitcli save [OPTIONS] [QUERY]

ARGUMENTS
    QUERY   Combination of type/object/category/entry
    
            type     is the localized name of an object type,
                     its constant or its numeric identifier
            object   title of numeric identifier
            category is the localized name of the category,
                     its contant or numeric identifier
            entry    is the numeric identifier
                     of an existing category entry

COMMAND OPTIONS
    -a ATTRIBUTE=VALUE,         Localized name or key of ATTRIBUTE
    --attribute=ATTRIBUTE=VALUE and its VALUE
                                (Use only if category is set)

COMMON OPTIONS
    -c FILE,            Include settings stored in a JSON-formatted
    --config=FILE       configuration file FILE; repeat option for more
                        than one FILE
    -s KEY=VALUE,       Add runtime setting KEY with its VALUE; separate
    --setting=KEY=VALUE nested keys with ".", for example "key1.key2=123";
                        repeat option for more than one KEY

    --no-colors         Do not print colored messages
    -q, --quiet         Do not output messages, only errors
    -v, --verbose       Be more verbose

    -h, --help          Print this help or information about a
                        specific command
    --version           Print version information

    -y, --yes           No user interaction required; answer questions
                        automatically with default values

EXAMPLES
    # Create new object with type "server" and title "mylittleserver":
    $ idoitcli save server/mylittleserver

    # Create/update attributes in a single-value category:
    $ idoitcli save server/mylittleserver/model \
        -a manufacturer=VendorA -a model=ModelA
    # Another one:
    $ idoitcli save server/mylittleserver/location \
        -a location="Data Center"

    # Update attributes in a multi-value category:
    $ idoitcli save server/mylittleserver/host\ address/1 \
        -a ipv4_address=192.168.42.23 \
        -a hostname=mylittleserver \
        -a domain=example.com

    # Use a template for an interactive mode:
    $ cat template.json
    {
        "templates": {
            "server": [
                {
                    "category": "model",
                    "attribute": "manufacturer"
                },
                {
                    "category": "model",
                    "attribute": "model"
                },
                {
                    "category": "host address",
                    "attribute": "ipv4_address"
                },
                {
                    "category": "host address",
                    "attribute": "hostname"
                },
                {
                    "category": "host address",
                    "attribute": "domain"
                },
                {
                    "category": "location",
                    "attribute": "location"
                }
            ]
        }
    }

    # Interactive mode:
    $ idoitcli save -c template.json
    Create/update CMDB objects and their category entries
    Type? server
    Title? mylittleserver
    Add more attributes? [Y/n] y
    [Model] Manufacturer? VendorA
    [Model] Model? ModelA
    [Host address] IPv4 address? 192.168.42.23
    [Host address] Hostname? mylittleserver
    [Host address] Domain? example.com
    [Location] Location? Data Center
    Link: http://cmdb.example.com/i-doit/?objID=42

@bheisig bheisig closed this as completed Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant