diff options
Diffstat (limited to 'src/pcp/openlmi-pcp-generate')
-rw-r--r-- | src/pcp/openlmi-pcp-generate | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/pcp/openlmi-pcp-generate b/src/pcp/openlmi-pcp-generate new file mode 100644 index 0000000..8c53512 --- /dev/null +++ b/src/pcp/openlmi-pcp-generate @@ -0,0 +1,68 @@ +#! /bin/sh + +# This script refreshes WBEM/CIM MOF & REG files from the current PCP PMNS, +# if necessary, and reloads the new MOF/REGs into the CIMMON. +# +# The PCP PMNS changes infrequently (when the sysadmin manuall installs or +# removes pcp PMDA (agent) modules in /var/lib/pcp/pmdas/*). +# +# This script encodes the PCP->CIM metric name-mapping convention of replacing +# dots with double-underscores, which lmi/pcp/metric.py will dutifully undo. + +_LOCALSTATEDIR=/var +_DATADIR=/usr/share +NAME=openlmi-providers +PYTHON2_SITELIB=/usr/lib/python2.7/site-packages + +PCP_PMNS=$_LOCALSTATEDIR/lib/pcp/pmns/root +PCP_HOST=${1-localhost} # or local:// for pcp 3.9+ +BASEMOFFILE=$_DATADIR/$NAME/60_LMI_PCP.mof +MOFREGDIR=$_LOCALSTATEDIR/lib/$NAME +STAMPFILE=$MOFREGDIR/stamp +MOFFILE=$MOFREGDIR/60_LMI_PCP_PMNS.mof +REGFILE=$MOFREGDIR/60_LMI_PCP_PMNS.reg +PROVIDER=$PYTHON2_SITELIB/lmi/pcp/metric.py + +if [ ! -f $PROVIDER ]; then + echo "Cannot find $PROVIDER" 1>&2 + exit 1 +fi + +set -e + +echo Refreshing PCP_Metric CIMMON classes from current PCP PMNS + +# quick liveness test +pcp -h $PCP_HOST + +if [ -s $PCP_PMNS -a $PCP_PMNS -nt $STAMPFILE ]; then + if [ -f $MOFFILE -a -f $REGFILE ]; then + echo Unregistering $BASEMOFFILE + echo Unregistering previous $MOFFILE + echo Unregistering previous $REGFILE + openlmi-mof-register unregister $BASEMOFFILE $MOFFILE $REGFILE || : + fi + + echo Generating $MOFFILE + pminfo -h $PCP_HOST | sed -e 's,\.,__,g' | + awk '{print "class PCP_Metric_" $1 " : PCP_MetricValue { } ;" }' > $MOFFILE + + echo Generating $REGFILE + pminfo -h $PCP_HOST | sed -e 's,\.,__,g' | + awk '{print "[PCP_Metric_" $1 "]" + print " provider: '$PROVIDER'" + print " location: pyCmpiProvider" + print " type: instance" + print " namespace: root/cimv2" + print " group: pcp" + print ""}' > $REGFILE + + echo Registering $BASEMOFFILE + echo Registering new $MOFFILE + echo Registering new $REGFILE + openlmi-mof-register register $BASEMOFFILE $MOFFILE $REGFILE 2>&1 | # filter out two noise diagnostics + egrep -v 'Warning: the instance already exists.|In this implementation, that means it cannot be changed.' || : + touch $STAMPFILE +else + echo Doing nothing, $PCP_PMNS older than $STAMPFILE +fi |