Command Line Usage¶
While most of zenpacklib’s functionality is as a Python module to be used as a library for helping build ZenPacks, zenpacklib.py also acts as a command line script to perform some useful actions.
You can choose to make zenpacklib.py executable then execute it as as script.
chmod 755 zenpacklib.py ./zenpacklib.py
Or you can leave it non-executable and execute it through python.
In either case you will get the following help.
Usage: zenpacklib.py <command> [options] Available commands and example options: # Check zenpack.yaml for errors. lint zenpack.yaml # Print yUML (http://yuml.me/) class diagram source based on zenpack.yaml. class_diagram yuml zenpack.yaml # Export existing monitoring templates to yaml. dump_templates ZenPacks.example.AlreadyInstalled # Convert a pre-release zenpacklib.ZenPackSpec to yaml. py_to_yaml ZenPacks.example.AlreadyInstalled # Print zenpacklib version. version
The following commands are supported:
- create: Create a new zenpacklib-enabled ZenPack source directory.
- lint: Provides syntax and correctness on a YAML file.
- class_diagram: Export yUML (yuml.me) class diagram from a YAML file.
- dump_templates: Export existing monitoring templates to YAML.
- py_to_yaml: Converts the Python syntax used in pre-release versions of zenpacklib to YAML.
- version: Print zenpacklib version.
The create command will create a source directory for a zenpacklib-enabled ZenPack. This will include a setup.py, MANIFEST.in, the namespace and module directories, and a zenpack.yaml in the module directory. It will also make a copy of zenpacklib.py inside the module directory. This ZenPack will be ready to be installed immediately though it will contain no functionality yet.
python zenpacklib.py create ZenPacks.example.MyNewPack
Running the above command would result in the following output.
Creating source directory for ZenPacks.test.ZPLTest2: - making directory: ZenPacks.test.ZPLTest2/ZenPacks/test/ZPLTest2 - creating file: ZenPacks.test.ZPLTest2/setup.py - creating file: ZenPacks.test.ZPLTest2/MAINFEST.in - creating file: ZenPacks.test.ZPLTest2/ZenPacks/__init__.py - creating file: ZenPacks.test.ZPLTest2/ZenPacks/test/__init__.py - creating file: ZenPacks.test.ZPLTest2/ZenPacks/test/ZPLTest2/__init__.py - creating file: ZenPacks.test.ZPLTest2/ZenPacks/test/ZPLTest2/zenpack.yaml - copying: ../../../zenpacklib.py to ZenPacks.test.ZPLTest2/ZenPacks/test/ZPLTest2
The lint command will check the provided YAML file for correctness. It checks that the provided file is syntactically-valid YAML, and it will also perform many others checks that validate that the contained entries, fields and their values are valid.
The following example shows an example of using an unrecognized parameter in a monitoring template.
python zenpacklib.py lint zenpack.yaml zenpack.yaml:47:9: Unrecognized parameter 'targetPythnoClass' found while processing RRDTemplateSpec
lint will provide no output if the provided YAML file is found to be correct.
The class_diagram command will use Classes and Relationships in the provided YAML file to output the source for a yUML (http://yuml.me) class diagram. For ZenPacks with a non-trivial class model this can provide a useful view of the model.
Using this example zenpack.yaml with class_diagram..
name: ZenPacks.example.NetBotz classes: NetBotzDevice: base: [zenpacklib.Device] NetBotzEnclosure: base: [zenpacklib.Component] NetBotzSensor: base: [zenpacklib.Component] class_relationships: - NetBotzDevice 1:MC NetBotzEnclosure - NetBotzDevice 1:MC NetBotzSensor - NetBotzEnclosure 1:M NetBotzSensor
Then running the following command..
python zenpacklib.py class_diagram yuml zenpack.yaml
Would result in the following yUML class diagram source. You can now paste this into http://yuml.me to see what it looks like.
# Classes [NetBotzDevice] [NetBotzEnclosure] [NetBotzSensor] # Inheritence [Device]^-[NetBotzDevice] [Component]^-[NetBotzEnclosure] [Component]^-[NetBotzSensor] # Containing Relationships [NetBotzDevice]++netBotzEnclosures-netBotzDevice[NetBotzEnclosure] [NetBotzDevice]++netBotzSensors-netBotzDevice[NetBotzSensor] # Non-Containing Relationships [NetBotzEnclosure]netBotzSensors-.-netBotzEnclosure++[NetBotzSensor]
The py_to_yaml command is designed for a very specific purpose that most people will not find useful. Earlier pre-release versions of zenpacklib required that the ZenPack be defined via a call to zenpacklib.ZenPackSpec() with Python data structures instead of via a YAML file. py_to_yaml converts this style of definition to a YAML file suitable for use with current versions of zenpacklib.
python zenpacklib.py py_to_yaml ZenPacks.example.BetterAlreadyBeInstalled
The dump_templates command is designed to export monitoring templates already loaded into your Zenoss instance and associated with a ZenPack. It will export them to the YAML format required for zenpack.yaml. It is up to you to merge that YAML with your existing zenpack.yaml. file.
python zenpacklib.py dump_templates ZenPacks.example.BetterAlreadyBeInstalled
The version command prints the zenpacklib version.
python zenpacklib.py version