---
title: "How to add a host and service using a perl script"
description: "Adding a host and service in OP5 Monitor can be automated using a Perl script with the HTTP API and LWP. The example script demonstrates creating a host, adding a service, and saving the configuration programmatically."
url: "https://docs.itrsgroup.com/docs/faq/op5/360020056934-op5-monitor-how-to-add-a-host-and-service-using-a-perl-script/index.html"
---
## Introduction

This example Perl script uses op5 Monitor's HTTP API and LWP to create a host, add a service, and save the committed configuration. The methods and techniques used in the example could easily be adapted to automatically create hosts from an Excel spreadsheet or inventory system.

## Files

| Description | File |
| --- | --- |
| Required Perl script | *[op5\_monitor-create\_example\_host.pl](/faq/downloads/op5/360020056934-inline-attachment-1-op5_monitor-create_example_host.pl)* |

## Troubleshooting

|  |  |
| --- | --- |
| Error | Fix |
| Can't locate LWP/UserAgent.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor\_perl /usr/share/perl5/vendor\_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./op5\_monitor-create\_example\_host.pl line 11. BEGIN failed--compilation aborted at ./op5\_monitor-create\_example\_host.pl line 11. | sudo yum install perl-libwww-perl |
| Can't locate JSON.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor\_perl /usr/share/perl5/vendor\_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./op5\_monitor-create\_example\_host.pl line 12. BEGIN failed--compilation aborted at ./op5\_monitor-create\_example\_host.pl line 12. | sudo yum install perl-JSON |
| Creating example host in Monitor...  501 Protocol scheme 'https' is not supported (LWP::Protocol::https not installed) Content-Type: text/plain Client-Date: Wed, 03 Aug 2022 04:21:28 GMT Client-Warning: Internal response  LWP will support https URLs if the LWP::Protocol::https module is installed. | sudo yum install perl-LWP-Protocol-https |
| Creating example host in Monitor...  500 Can't connect to 192.168.100.22:443 Content-Type: text/plain Client-Date: Wed, 03 Aug 2022 04:40:53 GMT Client-Warning: Internal response  Can't connect to 192.168.100.22:443 | In our instance, this was caused by an invalid SSL certificate in OP5 Monitor.  To bypass the certificate checks you can add:  $ua->ssl\_opts(verify\_hostname => 0);    Example:  my $ua = LWP::UserAgent->new; $ua->ssl\_opts(verify\_hostname => 0); my $json = new JSON; |

## Related downloads

- [op5_monitor-create_example_host.pl](/faq/downloads/op5/360020056934-360030010773-op5_monitor-create_example_host.pl)


