Red Hat Training

A Red Hat training course is available for Red Hat JBoss Operations Network

21.3. ドリフトの調整

ドリフトを修正するには、UI でアラートを定義し、実行できる CLI スクリプトをアップロードします(ドリフトが検出されるたびに自動的に)。スクリプトはすべて、バックアップバンドルをリソースにデプロイするだけで、さまざまな方法があります。
この例では、すべての基本的なステップを実行します。これは、アラートからリソース情報をプルし、バンドルバージョンを検索し、リソースにデプロイします。このスクリプトの 1 つは、ログファイルを書き込み、修正をトリガーしたアラート情報をキャプチャーすることです。
このスクリプトは、アラート定義の作成時に直接アップロードできます。スクリプトをアップロードする前に、誤差定義の設定時に作成したバンドルの宛先およびバンドルバージョンに変数を設定してください。
// - The 'alert' variable is seeded by the alert sender

// SET THESE VARIABLES
var bundleDestinationName = 'drift destination'
var bundleVersion = 1.0
var logFile = '/tmp/alert-cli-demo/logs/alert-' + alert.id + '.log'

// Log what we're doing to a file tied to the fired alert id
//
var e = exporter
e.setTarget( 'raw', logFile )

// Dump the alert
//
e.write( alert )

// get a proxy for the alerted-on Resource
//
var alertResource = ProxyFactory.getResource(alert.alertDefinition.resource.id)

// Dump the resource
//
e.write( " " )
e.write( alertResource )


// Remediate file

// Find the Bundle Destination
//
var destCrit = new BundleDestinationCriteria()
destCrit.addFilterName( bundleDestinationName )
var result = BundleManager.findBundleDestinationsByCriteria( destCrit )
var dest = result.get( 0 )

// Find the Bundle Version
//
var versionCrit = new BundleVersionCriteria()
versionCrit.addFilterVersion( bundleVersion )
result = BundleManager.findBundleVersionsByCriteria( versionCrit )
var ver = result.get( 0 )

// Create a new Deployment for the bundle version and the destination
//
var deployment = BundleManager.createBundleDeployment(ver.getId(), dest.getId(), 'remediate drift', new Configuration())

// Schedule a clean deploy of the deployment. This will wipe out the edited file and lay down a clean copy
//
BundleManager.scheduleBundleDeployment(deployment.getId(), true)

e.write( " " )
e.write( "REMEDIATION COMPLETE!" )