Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
f99b7e9
renaming webapplication.py into webApplication.py
May 12, 2015
b4fca70
renaming part 2
May 12, 2015
09bef07
typo
May 12, 2015
d9055e5
Comments were the other way around
May 12, 2015
f54e2da
Added Organization, DeliveryModel and all find_organization methods
May 12, 2015
7b7dc1b
Added enclosure and location
May 12, 2015
161633f
Removing debug commands
May 12, 2015
d3aa393
Added Brand and find_brand
May 12, 2015
936c56a
Added Brand
May 12, 2015
95175ab
Updated OSFamily and related functions
JulienNauroy May 13, 2015
1dae68e
Added OSVersion and related functions
JulienNauroy May 13, 2015
fc63964
Added OSLicence and related methods
JulienNauroy May 13, 2015
edb7371
Found that "provider" is in fact "Organization" for Service. Problem …
JulienNauroy May 13, 2015
dc20b90
corrected typos
JulienNauroy May 13, 2015
5e2f3c0
added partial list of missing classes to be processed later
JulienNauroy May 13, 2015
213a040
Bug solved with finding element by name
May 16, 2015
1275c6f
Corrected a typo
JulienNauroy Dec 3, 2015
e4b9fee
Added the Person class into the API.
JulienNauroy Dec 3, 2015
411da5d
wrong comments
JulienNauroy Dec 5, 2015
eac770c
Wrong class name: Localization => Location
JulienNauroy Dec 5, 2015
c01574e
Forgot the find_organization method
JulienNauroy Dec 5, 2015
04a4cff
Allowed getting the list element types given the dict entry to read, …
JulienNauroy Dec 5, 2015
8246b3b
Completed the Person type.
JulienNauroy Dec 5, 2015
d756fd0
functional CIs can now be read
JulienNauroy Dec 5, 2015
e6fd799
Added Team and Incident classes
JulienNauroy Dec 5, 2015
98ad42b
Added OtherSoftware to the list of supported classes
JulienNauroy Dec 5, 2015
fd76d23
Updated the contacts_list class type in diverse classes.
JulienNauroy Dec 5, 2015
86c362d
Recurse subclasses when looking for subclasses of ItopapiPrototype. M…
JulienNauroy Dec 6, 2015
b35722d
Added DBserver as a subclass of OtherSoftware
JulienNauroy Dec 6, 2015
a813af6
Forgot to remove the debug prints
JulienNauroy Dec 6, 2015
ba9b130
Updated the list of missing classes
JulienNauroy Dec 7, 2015
bbd1e0f
New ito2centreon connector
JulienNauroy Dec 7, 2015
689ea22
First try at synchronizing servers and VMs
JulienNauroy Dec 7, 2015
0b3036d
ignore local pylint script
JulienNauroy Dec 8, 2015
be6c9e5
Now Synchronizing servers and virtual machines
JulienNauroy Dec 8, 2015
908b1b3
Bidirectional sync for contacts, contact groups and servers
JulienNauroy Dec 8, 2015
b4dd0d6
Add only servers in production and remove servers no longer in produc…
JulienNauroy Dec 9, 2015
dfe397b
Making more clear the vocabularies between Itop and Centreon
JulienNauroy Dec 9, 2015
bfb2609
Identified what "agent" is in an incident
JulienNauroy Jan 9, 2016
3d30e30
Merge branch 'master' into features/itop2centreon
JulienNauroy Jan 9, 2016
26229e5
Added owerSource
JulienNauroy Jan 9, 2016
f820553
Forgot a return statement in many places
JulienNauroy Jan 9, 2016
4fbed19
Now that the PowerSource is defined, the method can be implemented an…
JulienNauroy Jan 9, 2016
d492290
More explicit TODO
JulienNauroy Jan 9, 2016
9dcaea0
Merge branch 'master' into features/itop2centreon
JulienNauroy Jan 9, 2016
73c4bb2
useless semicolon
JulienNauroy Jan 10, 2016
13aa92d
First attempt at connecting VCenter with iTop. To be continued soon.
JulienNauroy Jan 13, 2016
37bd1f2
Forgot to add the unsecure parameter to the example configuration file.
JulienNauroy Jan 14, 2016
76c5e40
Started adding support for sync modes
JulienNauroy Jan 14, 2016
94757c0
forgot to remove the debug print
JulienNauroy Jan 14, 2016
331be9c
forgot to remove the debug print
JulienNauroy Jan 14, 2016
0ac6705
working on it
JulienNauroy Jan 14, 2016
f093e3f
find_by_name now returns a singleton and not a list with one instance…
JulienNauroy Jan 14, 2016
6b890b2
Merge branch 'master' into features/connectors
JulienNauroy Jan 14, 2016
50300b2
Added model for a server Farm
JulienNauroy Jan 14, 2016
cd7ce78
Merge branch 'master' into features/connectors
JulienNauroy Jan 14, 2016
d591768
Still working on it
JulienNauroy Jan 14, 2016
7c8ecb2
Worked a lot on vcenter2itop. Not finished yet though.
JulienNauroy Jan 16, 2016
25a6936
Added model for Hypervisor
JulienNauroy Jan 16, 2016
6152379
Merge branch 'master' into features/connectors
JulienNauroy Jan 16, 2016
e8a57e7
Now vms can also be linked to hypervisors by default, not only farms
JulienNauroy Jan 16, 2016
1a1711d
Nearly working with cluster and vm sync.
JulienNauroy Jan 18, 2016
1026c9f
Now update also works well + refactoring.
JulienNauroy Jan 23, 2016
36d4440
Now syncing OS and vendor
JulienNauroy Jan 24, 2016
9316146
Nearly done. Now using the description field as a placeholder for ext…
JulienNauroy Jan 25, 2016
9f9636a
Synchronization from VCenter to iTop is fully operational. Tested wit…
JulienNauroy Jan 29, 2016
cc9524a
updated license authors
JulienNauroy Jan 29, 2016
708f0e3
minor typo
JulienNauroy Jan 29, 2016
8cf9b47
renamed itop-cli.cfg to python-itop-api.cfg to better reflect it's ge…
JulienNauroy Jan 29, 2016
8750f26
updated the setup scrit
JulienNauroy Jan 29, 2016
60eab29
Started updating the README file in order to include the two new scri…
JulienNauroy Jan 29, 2016
40a1384
Updated authors
JulienNauroy Jan 29, 2016
3c03151
english
JulienNauroy Jan 30, 2016
8f8ee36
Added a new HasOrganization feature (mixin) and updated the data mode…
JulienNauroy Jan 30, 2016
7c6ce1c
english
JulienNauroy Jan 30, 2016
8e13cc8
removed unused ItopapiUnimplementedMethod
JulienNauroy Jan 30, 2016
f63a57b
Removed unused load_from_json_quattor
JulienNauroy Jan 30, 2016
e2cda78
Added blank space
JulienNauroy Jan 30, 2016
68855b6
added the HasLocation mixin and updated data model
JulienNauroy Jan 30, 2016
2542f84
added HasBrand mixin and updated data model
JulienNauroy Jan 30, 2016
f7ffdd1
error in copy/paste
JulienNauroy Jan 30, 2016
51d0181
Added HasModel mixin and updated data model.
JulienNauroy Jan 30, 2016
774dae5
Added HasOSFamily mixin and updated data model.
JulienNauroy Jan 30, 2016
11cfdf2
Added HasOSVersion mixin and updated data model.
JulienNauroy Jan 30, 2016
f325945
Added HasOSLicence (sic) mixin and updated data model.
JulienNauroy Jan 30, 2016
f77b74c
Added HasVirtualHost mixin and updated data model.
JulienNauroy Jan 30, 2016
aaaa0a2
Added HasRack mixin and updated data model.
JulienNauroy Jan 30, 2016
34ce780
Added HasEnclosure mixin and updated data model.
JulienNauroy Jan 30, 2016
752c09b
Organization was not well referenced in these classes
JulienNauroy Jan 30, 2016
82cf493
Added HasServer mixin and updated data model.
JulienNauroy Jan 30, 2016
1ac277d
Added HasFarm mixin and updated data model.
JulienNauroy Jan 30, 2016
9ea1f6c
Added HasWebServer mixin and updated data model.
JulienNauroy Jan 30, 2016
655a88c
added HasDeliveryModel mixin and updated data model.
JulienNauroy Jan 30, 2016
709ac33
Added HasSoftwareLicence (sic) mixin and updated data model.
JulienNauroy Jan 30, 2016
6097502
Added HasSoftware mixin and updated data model.
JulienNauroy Jan 30, 2016
86e883e
Forgot to update this class' data model.
JulienNauroy Jan 30, 2016
8657c6c
Added HasTeam mixin and updated data model.
JulienNauroy Jan 30, 2016
9ddb802
Added HasAgent mixin and updated data model.
JulienNauroy Jan 30, 2016
dfcef95
Fixed errors in the comments
JulienNauroy Jan 30, 2016
d853ddc
Added HasManager fixin and updated data model.
JulienNauroy Jan 30, 2016
17db42e
Now find() is able to search for generic classes (first use case in n…
JulienNauroy Jan 31, 2016
57428f1
Worked on the inheritance model and added a lot of new classes
JulienNauroy Jan 31, 2016
e06ec65
Added some more classes to the data model.
JulienNauroy Feb 1, 2016
d47c860
Added HasSystem mixin and updated classes accordingly.
JulienNauroy Feb 1, 2016
218a009
Finished with the Typology and started NetworkDevices
JulienNauroy Feb 2, 2016
4575a49
Added network appliances to the model.
Feb 2, 2016
a124014
Even more classes
Feb 2, 2016
e4c5a8c
Now the VLAN should be fetched correctly from the PhysicalInterface
Feb 2, 2016
2927a55
Fixed wrong case in file names + executable files.
Feb 5, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
.idea
*.pyc
itop-cli.cfg
python-itop-api.cfg
MANIFEST
dist
build
Makefile
python_itop_api.egg-info
python_itop_api.egg-info
pylint.bat
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015, Guillaume Philippon
Copyright (c) 2015-2016, Guillaume Philippon and Julien Nauroy

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include itop-cli.cfg.example
include python-itop-api.cfg.example
96 changes: 59 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,72 @@
# python-itop-api
API python pour iTop via l'interface REST
Python API to interface iTop to various other tools.
Three command-line scripts are currently provided: itop-cli, vcenter2itop and itop2centreon

## itop-cli
itop-cli is a CLI (command line interface) to iTop REST interface. We can use it to list the content
of iTop classes with the command
itop-cli is a generic CLI (command line interface) to the iTop REST interface.
You can use it to list the contents of iTop classes with the command

user@machine> itop-cli --classes server rack

You can also search some specific instance with option --find

user@machine> itop-cli --classes server --find host.domain.com

You can have a look of more option with command --help
You can have a look at the options with the --help command

user@machine> itop-cli --help

usage: itop-cli [-h] [--hostname HOSTNAME] [--username USERNAME]
[--password PASSWORD] [--config CONFIG_FILE]
[--classes [ITOP-CLASS [ITOP-CLASS ...]]]
[--find INSTANCE [INSTANCE ...]] [--delete INSTANCE INSTANCE]
[--organization ORGANIZATION] [--import URI] [--format FORMAT]

python CLI for iTop REST api

optional arguments:
-h, --help show this help message and exit

itop:
--hostname HOSTNAME hostname of iTop server
--username USERNAME username for iTop authentication
--password PASSWORD password for iTop authentication

cli:
--config CONFIG_FILE configuration file CLI must use (default = ./itop-
cli.cfg)
--classes [ITOP-CLASS [ITOP-CLASS ...]]
iTop classes to use
--find INSTANCE [INSTANCE ...]
Find and display information about a given class
instance givenits name or ID
--delete INSTANCE INSTANCE
Delete an instance given its class name and instance
ID
--organization ORGANIZATION
iTop organization to use

import:
--import URI URI of file to import
--format FORMAT Format of file you want import
usage: itop-cli [-h] [--hostname HOSTNAME] [--username USERNAME]
[--password PASSWORD] [--organization ORGANIZATION-NAME]
[--virtualhost VIRTUAL-HOSTNAME] [--config CONFIG_FILE]
[--classes [ITOP-CLASS [ITOP-CLASS ...]]]
[--find INSTANCE [INSTANCE ...]] [--delete] [--import-uri URI]
[--import-stdin] [--format FORMAT] [--save]
[--prevent-duplicates]

python CLI for iTop REST api

optional arguments:
-h, --help show this help message and exit

itop:
--hostname HOSTNAME hostname of iTop server
--username USERNAME username for iTop authentication
--password PASSWORD password for iTop authentication
--organization ORGANIZATION-NAME
iTop organization to use
--virtualhost VIRTUAL-HOSTNAME
Itop's virtual host name for VMs

cli:
--config CONFIG_FILE configuration file CLI must use (default = ./itop-
cli.cfg)
--classes [ITOP-CLASS [ITOP-CLASS ...]]
iTop classes to use
--find INSTANCE [INSTANCE ...]
Find and display information about a given class
instance givenits name or ID
--delete Delete all instances previously loaded
--save Save the instances loaded through import
--prevent-duplicates Check if objects with the same name already exist
before savingand don't save in this case

import:
--import-uri URI URI of file to import
--import-stdin import data from STDIN
--format FORMAT Format of file you want import


## vcenter2itop
vcenter2itop focuses on extracting data from a VMWare VCenter cluster and importing it into iTop.
It synchronises Farms, Servers, Hypervisors and VirtualMachines present in a VCenter as well as Brands, Models, OS Families and Versions.
It has a dependency on the pyVmomi module.

All parameters are set into the common python-itop-api.cfg script. vcenter2itop is then simply runs this way:

user@machine> vcenter2itop

# itop2centreon
itop2centreon is an attempt at synchronizing iTop with the Centreon monitoring system through its CLAPI (command-line API) interface.
For now, it synchronizes the list of machines (Servers and VMs) and contacts.
It can serve as a kickstart script for your own synchronization mechanism.
21 changes: 0 additions & 21 deletions itop-cli.cfg.example

This file was deleted.

205 changes: 205 additions & 0 deletions itop2centreon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
#!/usr/bin/env python
# -*- coding: utf8 -*-fr
# pylint: disable=invalid-name
"""
itop2centreon is a basic CLI interface to export itop data into centreon
"""

__version__ = '1.0'
__authors__ = ['Julien Nauroy <julien.nauroy@u-psud.fr>']

from itopapi import ItopapiController, ItopapiConfig, UnsupportedImportFormat
from itopcli import load_configuration_cli, ItopcliConfig, NeedMoreArgs
from itopapi.model import *
import subprocess


def csv_to_dict(csv):
lines = csv.splitlines()
headers = lines.pop(0).split(';')
dict = []
for line in lines:
dict_line = {}
for i, val in enumerate(line.split(';')):
dict_line[headers[i]] = val.decode('utf-8')
dict.append(dict_line)
return dict


def run_clapi_list_command(object):
out, err = subprocess.Popen([ItopapiConfig.centreon_clapi_path,
'-u', ItopapiConfig.centreon_username,
'-p', ItopapiConfig.centreon_password,
'-o', object,
'-a', 'show'],
stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()
return csv_to_dict(out)


def run_clapi_action_command(obj, action, values):
out, err = subprocess.Popen([ItopapiConfig.centreon_clapi_path,
'-u', ItopapiConfig.centreon_username,
'-p', ItopapiConfig.centreon_password,
'-o', obj,
'-a', action,
'-v', ';'.join(str(x.encode('utf-8')) for x in values)],
stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()
if out == "":
return True
else:
print "Error running action command:"
print out
exit(0)


def main():
"""
Main function
"""

######################################
# Load Itop & Centreon configuration #
######################################
try:
load_configuration_cli()
except NeedMoreArgs as e:
print "Error: {}".format(e.message)
exit(1)


####################
# Some value check #
####################
if ItopapiConfig.username is None\
or ItopapiConfig.password is None:
print "Error: Itop Username/Password missing"
exit(1)
if ItopapiConfig.centreon_username is None\
or ItopapiConfig.centreon_password is None\
or ItopapiConfig.centreon_clapi_path is None:
print "Error: Centreon Username/Password/Path missing"
exit(1)

controller = ItopapiController()


#####################
# Synchronize Teams #
#####################
print "Synchronizing Itop teams / Centreon contact groups..."
centreon_contact_groups = run_clapi_list_command("CG")
itop_teams = ItopapiTeam.find_all()
for team in itop_teams:
group_exists = False
for contact_group in centreon_contact_groups:
if team.name == contact_group['name']: group_exists = True
if not group_exists:
print u"adding team {0} as a contact group".format(team.friendlyname.format('utf-8'))
run_clapi_action_command('CG', 'add', [team.name, team.name + ' (from Itop)'])

###################################
# Cleanup Centreon Contact Groups #
###################################
print "Cleaning up Centreon contact groups..."
all_contact_group_names = map(lambda s: s.name, itop_teams)
for contact_group in centreon_contact_groups:
if contact_group['name'] not in all_contact_group_names and contact_group['name'] != 'Supervisors':
print u"deleting contact group {0} as is is not defined in itop".format(contact_group['name'].format('utf-8'))
run_clapi_action_command('CG', 'DEL', [contact_group['name']])

#######################
# Synchronize Persons #
#######################
print "Synchronizing Itop persons / Centreon contacts..."
centreon_contacts = run_clapi_list_command("contact")
# Can't get persons from teams since their email is not listed in team.persons_list
itop_persons = ItopapiPerson.find_all()
for person in itop_persons:
# All persons should have an email
if person.email is None or '@' not in person.email:
continue

contact_alias = person.email.split('@')[0]
contact_exists = False
for contact in centreon_contacts:
if person.email == contact['email']: contact_exists = True
if not contact_exists:
print u"adding person {0} as a contact".format(person.friendlyname.format('utf-8'))
run_clapi_action_command('contact', 'add', [person.friendlyname, contact_alias, person.email, '', '0', '1', 'en_US', 'ldap'])
# In all cases, add the contact to the contacts list and set various parameters
for team in person.team_list:
run_clapi_action_command('CG', 'addcontact', [team.team_name, contact_alias])
run_clapi_action_command('contact', 'setParam', [contact_alias, 'enable_notifications', '1'])
run_clapi_action_command('contact', 'setParam', [contact_alias, 'hostnotifcmd', 'host-notify-by-email'])
run_clapi_action_command('contact', 'setParam', [contact_alias, 'hostnotifopt', 'd,u,r'])
run_clapi_action_command('contact', 'setParam', [contact_alias, 'svcnotifcmd', 'service-notify-by-email'])
run_clapi_action_command('contact', 'setParam', [contact_alias, 'servicenotifopt', 'w,u,c,r,f'])

#############################
# Cleanup Centreon Contacts #
#############################
print "Cleaning up Centreon contacts..."
all_contact_aliases = map(lambda s: '' if s.email is None else s.email.split('@')[0], itop_persons)
for contact in centreon_contacts:
if contact['alias'] not in all_contact_aliases and contact['alias'] != 'admin':
print u"deleting contact {0} as is is not defined in itop".format(contact['alias'].format('utf-8'))
run_clapi_action_command('contact', 'DEL', [contact['alias']])

def sync_servers(servers, centreon_hosts):
for server in servers:
if server.managementip is None or server.managementip == '':
continue
server_exists = False
for host in centreon_hosts:
if server.name == host['name']: server_exists = True
if server.status != 'production':
if server_exists:
# Remove servers no longer in production
print u"removing {0} as a host as its status is {1}".format(server.name.format('utf-8'), server.status)
run_clapi_action_command('HOST', 'DEL', [server.name])
continue

if not server_exists:
print u"adding {0} as a host".format(server.name.format('utf-8'))
run_clapi_action_command('HOST', 'ADD', [server.name, server.description, server.managementip,
'generic-host', 'central', ''])

# Set the server parameters
run_clapi_action_command('HOST', 'setParam', [server.name, 'check_period', '24x7'])
# Set the contacts
for contact in server.contacts_list:
if type(contact) is ItopapiTeam:
run_clapi_action_command('HOST', 'addContactGroup', [server.name, contact.contact_name])
else:
run_clapi_action_command('HOST', 'addContact', [server.name, contact.contact_id_friendlyname])

#######################
# Synchronize Servers #
#######################
print "Synchronizing Itop servers / Centreon hosts..."
centreon_hosts = run_clapi_list_command("HOST")
itop_servers = ItopapiServer.find_all()
sync_servers(itop_servers, centreon_hosts)

###############################
# Synchronize VirtualMachines #
###############################
print "Synchronizing Itop VMs / Centreon hosts..."
itop_vms = ItopapiVirtualMachine.find_all()
sync_servers(itop_vms, centreon_hosts)

##########################
# Cleanup Centreon Hosts #
##########################
print "Cleaning up Centreon hosts..."
all_servers_names = map(lambda s: s.name, itop_servers + itop_vms)
for host in centreon_hosts:
if host['name'] not in all_servers_names:
print u"deleting host {0} as is is not defined in itop".format(host['name'].format('utf-8'))
run_clapi_action_command('HOST', 'DEL', [host['name']])

return 0


if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions itopapi/controller/ItopapiController.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def load_one(self, itop_class, id_instance):
if id_instance.isdigit():
instance = model.find(id_instance)
else:
instance = model.find(model.find_by_name(id_instance))
instance = model.find_by_name(id_instance)
if instance is not None:
self.data.extend(instance)
self.data.append(instance)

def delete(self):
"""
Expand Down
Loading