Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for network facts #182

Closed
Noname2244 opened this issue Oct 4, 2018 · 15 comments
Closed

Support for network facts #182

Noname2244 opened this issue Oct 4, 2018 · 15 comments

Comments

@Noname2244
Copy link

Ansible-cmdb is hardcoded for the columns:
" Name Groups Cust DTAP Comment Ext ID FQDN Main IP All IPv4 All IPv6 OS Kernel Arch Virt CPU type vCPUs RAM [GiB] Mem Usage Swap Usage Disk usage PhysDisk size Nr of Ifaces Timestamp Product Name Product Serial"

if one wants this to work with out put from ie ios_facts you need to adjust the columns to ie:
"ansible_net_hostname"
"ansible_net_serialnum"
"ansible_net_model"
"ansible_net_stacked_models"
"ansible_net_stacked_serialnums"
"ansible_net_version"

Is this possible?

@Noname2244
Copy link
Author

Seems that it would be possible with custom templates.

https://ansible-cmdb.readthedocs.io/en/latest/usage/#custom-templates
I just need to figure out how to use that

@fboender
Copy link
Owner

Adding columns by creating custom templates is a bit involved right now. I'm currently looking into an easier method of adding custom columns. Probably this will be something like a configuration file containing simple column definitions that you can pass with a parameter. The columns would then automatically be added to the selected template.

@fboender fboender self-assigned this Oct 24, 2018
@fboender
Copy link
Owner

I've implemented a --cust-cols argument that lets you specify custom columns in a json file. It should prove to be a much easier undertaking than creating custom templates.

Documentation can be found here (You may need to refresh the page at ReadTheDocs to bypass caching).

I think this should be enough functionality to implement the custom columns you'd like to see. Can you give it a try, see if everything is working as expected and is clearly documented? If you need any help, please let me know.

@Noname2244
Copy link
Author

Noname2244 commented Oct 29, 2018

Nice! Can it read the json data from ansible output from ie. ios facts?

Seems so!

"jsonxs": "ansible_facts.ansible_apparmor.status"

I have to try this asap :)

@fboender
Copy link
Owner

Can it read the json data from ansible output from ie. ios facts?

Yes, this shouldn't be a problem. I don't know if IOS facts are native to ansible, or if you're creating custom facts with /etc/ansible/facts.d entries (i.e. "host local facts"), but both should be supported. For example, we have a host local fact that checks if Ferm (a firewall rule generator) is installed. It can be access via jsonxs with "ansible_facts.ansible_local.firewall_status.ferm_enabled".

@Noname2244
Copy link
Author

Noname2244 commented Oct 30, 2018

Is the patch avail via pip install?

....
Successfully installed ansible-cmdb-1.28
:~/script/ansible/hm$ ansible-cmdb -C cust_cols.json out/ >overview.html
Usage: ansible-cmdb.py [option] <dir> > output.html

ansible-cmdb.py: error: no such option: -C
:~/script/ansible/hm$
$ ansible-cmdb --help
Usage: ansible-cmdb.py [option] <dir> > output.html

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -t TEMPLATE, --template=TEMPLATE
                        Template to use. Default is 'html_fancy'
  -i INVENTORY, --inventory=INVENTORY
                        Inventory to read extra info from
  -f, --fact-cache      <dir> contains fact-cache files
  -p PARAMS, --params=PARAMS
                        Params to send to template
  -d, --debug           Show debug output
  -q, --quiet           Don't report warnings
  -c COLUMNS, --columns=COLUMNS
                        Show only given columns
  --exclude-cols=EXCLUDE_COLUMNS
                        Exclude cols from output

@fboender
Copy link
Owner

No not yet. You'll have to git clone master or wait for the new release. I've also made some changes to make the feature more powerful (template fragments in the column definition) which I still need to test and document.

@fboender
Copy link
Owner

I've made a few small changes in the custom columns functionality:

  • The custom columns file is no longer JSON, but rather Python code, so that multi-line strings are properly supported. Not much changes, as Python code is almost backwards compatible with JSON. The only thing that's different is that true and false should be capitalized now. See https://ansible-cmdb.readthedocs.io/en/latest/usage/#custom-columns for a new example configuration file.
  • There is now support for template fragments for rendering columns in addition to the jsonxs method. Template fragments are more powerful, but also a bit more complicated. Again, see the ReadTheDocs documentation for an example.

I'll be releasing a new version of Ansible-cmdb soon. If you want to try it in the meantime, you'll have to use the git master branch.

I'm going to go ahead and close this issue. If you run into any problems or need any additional help, don't hesitate to reopen this issue!

@Noname2244
Copy link
Author

Can you see whats wrong with the formatting here?

/usr/bin/ansible-cmdb -C cust_cols.json out/ >overview.html
Invalid custom columns file: cust_cols.json
malformed string
fff:~/script/ansible/hm$ cat cust_cols.json
[
{
"title": "Hostname",
"id": "hostname",
"sType": "string",
"visible": true,
"jsonxs": "ansible_net_hostname"
},
{
"title": "Model",
"id": "modeltype",
"sType": "string",
"visible": true,
"jsonxs": "ansible_net_model"
},
{
"title": "Version",
"id": "version",
"sType": "string",
"visible": true,
"jsonxs": "ansible_net_version"
},
{
"title": "Serialnumber",
"id": "serialnumber",
"sType": "string",
"visible": true,
"jsonxs": "ansible_net_serialnum"
}
]

@Noname2244
Copy link
Author

example of inventory json

{
"ansible_facts": {
"ansible_net_filesystems": [
"flash:"
],
"ansible_net_gather_subset": [
"hardware",
"default"
],
"ansible_net_hostname": "xxxxx",
"ansible_net_image": "flash:c800-universalk9-mz.SPA.154-2.T1.bin",
"ansible_net_memfree_mb": 174713,
"ansible_net_memtotal_mb": 304000,
"ansible_net_model": "C881-K9",
"ansible_net_serialnum": "FGL2xxxxx",
"ansible_net_version": "15.4(2)T1"
},
"changed": false,
"failed": false
}

@fboender
Copy link
Owner

"visible": true,

true should be capitalized (True). It's no longer JSON, but rather Python code, and Python expects True.

@Noname2244
Copy link
Author

Noname2244 commented Nov 15, 2018

image

How do I remove the default columns? I only want the custom columns .

I will try the --exclude-cols option.

@Ondjultomte
Copy link

Ondjultomte commented Sep 10, 2019

This doesnt work any more.

the custom coloums are there but there is no data visible
ansible-cmdb doesnt through any error either so there is not much to go on debugging wise.

@staanaeq
Copy link

Hello everyone,

ansible-cmdb is very useful, just a question on this if this can be customized for ios_facts? This would be very helpful for us network engineers. Thanks a lot! :)

@pgmodusbox
Copy link

pgmodusbox commented Jan 26, 2022

In my case it's giving all zero zero values for all the metrics, how to fix ? can any help/suggest ?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants