[1027] | 1 | #!/usr/bin/env python
|
---|
| 2 |
|
---|
| 3 | # get client properties for bacula
|
---|
| 4 |
|
---|
[1094] | 5 | import logging
|
---|
[1027] | 6 | import subprocess
|
---|
| 7 | import json
|
---|
| 8 | from pprint import pprint
|
---|
| 9 |
|
---|
| 10 | opsi={
|
---|
| 11 | 'server': "https://degdepot2.joergs:4447/rpc",
|
---|
| 12 | 'username': "joergs",
|
---|
| 13 | 'password': "linuxlinux",
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | # "-d"
|
---|
| 17 | opsiCallPrefix=[ "opsi-admin", "-a", opsi['server'], "-u", opsi['username'], "-p", opsi['password'] ]
|
---|
| 18 |
|
---|
| 19 | opsiCallClientsWithBacula=[ "method", "productOnClient_getObjects", "[]", '{"productId":"bacula", "installationStatus": "installed"}']
|
---|
| 20 |
|
---|
| 21 | opsiCallClientBaculaProperties=[ "method", "getProductProperties_hash", "bacula" ]
|
---|
| 22 |
|
---|
[1028] | 23 |
|
---|
| 24 | def write_client_conf( client, properties ):
|
---|
| 25 | #Client {
|
---|
| 26 | #Name = ting-fd
|
---|
| 27 | #Address = ting.dass-it
|
---|
| 28 | #FDPort = 9102
|
---|
| 29 | #Catalog = MyCatalog
|
---|
| 30 | #Password = "D5w2V5w6B8a9H5Z"
|
---|
| 31 | #File Retention = 6 months
|
---|
| 32 | #Job Retention = 6 months
|
---|
| 33 | #AutoPrune = yes
|
---|
| 34 | #}
|
---|
| 35 | params = [ "FDPort", "Catalog", "FileRetention", "JobRetention", "AutoPrune" ]
|
---|
| 36 | print "Client {"
|
---|
| 37 | print " Name =", properties['filedaemon_full_name']
|
---|
| 38 | print " Address =", client['clientId']
|
---|
| 39 | # ipAddress: method host_getObjects [] '{"id":client['clientId']}'
|
---|
| 40 | #print " # Address =", ipAddress
|
---|
| 41 | print " Password =", properties['filedaemon_full_password']
|
---|
| 42 | for i in params:
|
---|
| 43 | try:
|
---|
| 44 | print " " + i + " = " + properties[i.lower()]
|
---|
| 45 | except KeyError:
|
---|
| 46 | print " # " + i + " = "
|
---|
| 47 | print "}"
|
---|
| 48 | print
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | def write_job_conf( client, properties ):
|
---|
| 54 | #Job {
|
---|
| 55 | #FileSet = "tingfileset"
|
---|
| 56 | #Name = "ting"
|
---|
| 57 | #Client = ting-fd
|
---|
| 58 | #JobDefs = "LaptopJob"
|
---|
| 59 | ## Write Bootstrap = "/var/lib/bacula/ting.bsr"
|
---|
| 60 | #}
|
---|
| 61 | params = [ "Fileset", "JobDefs" ]
|
---|
| 62 | print "Job {"
|
---|
| 63 | print " Name =", client['clientId'] + "-job"
|
---|
| 64 | print " Client =", properties['filedaemon_full_name']
|
---|
| 65 | for i in params:
|
---|
| 66 | print " ",
|
---|
| 67 | try:
|
---|
| 68 | if not properties[i.lower()]:
|
---|
| 69 | print "#",
|
---|
| 70 | print i + " = " + properties[i.lower()]
|
---|
| 71 | except KeyError:
|
---|
| 72 | print "# " + i + " = "
|
---|
| 73 | print "}"
|
---|
| 74 | print
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | #
|
---|
| 79 | # main
|
---|
| 80 | #
|
---|
| 81 |
|
---|
[1094] | 82 | #logging.basicConfig(format='%(asctime)s %(levelname)8s %(message)s')
|
---|
| 83 | logging.basicConfig(format='%(message)s')
|
---|
| 84 | logger = logging.getLogger(__name__)
|
---|
| 85 | #logger.setLevel(logging.INFO)
|
---|
| 86 | logger.setLevel(logging.DEBUG)
|
---|
| 87 |
|
---|
| 88 | logger.debug( "start" )
|
---|
| 89 |
|
---|
[1027] | 90 | try:
|
---|
| 91 | clientsWithBacula=json.loads( subprocess.check_output( opsiCallPrefix + opsiCallClientsWithBacula ) )
|
---|
[1094] | 92 | #except subprocess.CalledProcessError as e:
|
---|
| 93 | except e:
|
---|
| 94 | logger.exception( "%s: failed:" %(clientId) )
|
---|
| 95 | exit(1)
|
---|
[1027] | 96 |
|
---|
[1094] | 97 | #pprint( clientsWithBacula )
|
---|
[1027] | 98 |
|
---|
| 99 | for client in clientsWithBacula:
|
---|
[1028] | 100 | clientId = client['clientId']
|
---|
[1027] | 101 |
|
---|
| 102 | try:
|
---|
| 103 | clientBaculaProperties=json.loads( subprocess.check_output( opsiCallPrefix + opsiCallClientBaculaProperties + [ client['clientId'] ] ) )
|
---|
[1094] | 104 | except ValueError as e:
|
---|
| 105 | logger.warn( "%s: no valid information found: %s" %(clientId, e) )
|
---|
| 106 | except subprocess.CalledProcessError as e:
|
---|
| 107 | logger.exception( "%s: failed:" %(clientId) )
|
---|
| 108 | #exit( 1 )
|
---|
| 109 | else:
|
---|
| 110 | #pprint( clientBaculaProperties )
|
---|
| 111 | write_client_conf( client, clientBaculaProperties )
|
---|
| 112 | write_job_conf( client, clientBaculaProperties )
|
---|
| 113 | logger.info( "%s: OK" % clientId )
|
---|
| 114 |
|
---|
| 115 | logger.debug( "finished" )
|
---|