├── .gitignore
├── LICENSE
├── README.md
├── docs
├── conf.py
├── index.rst
└── reference.rst
├── examples
├── README.md
├── _host
├── cmdb_antivirus_profile.py
├── cmdb_firewall_address-add_address.py
├── cmdb_firewall_address.py
├── cmdb_firewall_addrgrp-add_addrgrp.py
├── cmdb_firewall_addrgrp.py
├── cmdb_firewall_policy-add_policy.py
├── cmdb_firewall_policy.py
├── cmdb_system_global-configure.py
├── cmdb_system_global.py
├── cmdb_system_interface-check_required_fields.py
├── cmdb_system_interface-configure.py
├── cmdb_system_interface.py
├── cmdb_user_local-add_user.py
├── cmdb_user_local.py
├── cmdb_vpn.ssl_settings-configure.py
├── cmdb_vpn.ssl_settings.py
├── monitor_firewall_policy-check_last_used.py
├── monitor_firewall_policy-lookup.py
├── monitor_firewall_policy.py
├── monitor_license_status.py
├── monitor_log_device_state.py
├── monitor_router_ipv4.py
├── monitor_system_available-interfaces.py
├── monitor_system_config-revision.py
├── monitor_system_config-revision_file.py
├── monitor_system_config-revision_save.py
├── monitor_system_config_backup-vdom.py
├── monitor_system_config_backup.py
├── monitor_system_config_restore.py
├── monitor_system_firmware.py
├── monitor_system_firmware_upgrade-local_file.py
├── monitor_system_firmware_upgrade-paths.py
├── monitor_system_firmware_upgrade.py
├── monitor_system_interface.py
├── monitor_system_os_reboot.py
├── monitor_system_os_shutdown.py
├── monitor_system_status.py
└── monitor_system_vmlicense_upload.py
├── gatepy
├── __init__.py
├── cmdb.py
├── gatepy.py
├── monitor.py
└── setup.py
├── requirements.txt
└── samples
├── README.md
├── cmdb_system_interface.py
├── monitor_firewall_policy_lookup.py
├── monitor_license_status.py
└── monitor_system_available-interfaces.py
/.gitignore:
--------------------------------------------------------------------------------
1 | ignore
2 | .DS_Store
3 | *.out
4 | *.lic
5 |
6 | # Python
7 | __pycache__/
8 | *.egg-info/
9 |
10 | # docs
11 | Makefile
12 | _build
13 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # gatepy - FortiGate Automation using REST API
2 |
3 | gatepy ultimate goal is to be a python script to facilitate the FortiGate administration using REST API, some use cases would include mass object creation, processing CSV files to quickly create URL lists and more. Feel free to suggest new use cases at the Issues section.
4 |
5 | The first releases will be in various use cases of self-contained scripts, after we have enough maturity the idea is to pack it all in a single tool that will call whatever auxiliar script is needed, but also give the option to use the task script regardless of a master script to control it.
6 |
7 | ## How To Use
8 |
9 | To clone and run the examples you'll need:
10 | * [Docker](https://www.docker.com/get-started)
11 | * [Git](https://git-scm.com)
12 | * [Python3](https://www.python.org/downloads/)
13 | * [pip](https://pip.pypa.io/en/stable/installing/)
14 |
15 | From your command line:
16 |
17 | ```bash
18 | # Pull and start docker image
19 | $ docker pull ubuntu:18.04
20 | $ docker run --name=gatepy_dev -it ubuntu:18.04
21 |
22 | # Install packages
23 | $ apt update
24 | $ apt install git python3 python3-pip python-dev libssl-dev libffi-dev vim
25 |
26 | # Clone this repository
27 | $ git clone https://github.com/barbosm/gatepy
28 |
29 | # Go into the repository
30 | $ cd gatepy
31 |
32 | # Install dependencies
33 | $ pip3 install -r requirements.txt
34 |
35 | # Edit _host to your FG details (IP and credentials)
36 | $ vim examples/_host
37 |
38 | # Load environment variables
39 | $ source examples/_host
40 |
41 | # Run the examples
42 | $ python3 examples/monitor_system_status.py
43 | ```
44 |
45 |
46 | ## Prerequisites
47 |
48 | * Change IP and credentials on _host file
49 | * Install python dependencies
50 |
51 |
52 | ## Documentation
53 | * [Module Reference](https://gatepy.readthedocs.io/en/latest/reference.html)
54 |
55 |
56 | ## Environment
57 |
58 | Tested on:
59 | * Mac OS X 10.10
60 | * python 3.5.2
61 | * FortiOS 6.0
62 | * fortiosapi 0.9.91
63 |
64 | It should work on different environments, just keep in mind the versions above.
65 |
--------------------------------------------------------------------------------
/docs/conf.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | #
3 | # Configuration file for the Sphinx documentation builder.
4 | #
5 | # This file does only contain a selection of the most common options. For a
6 | # full list see the documentation:
7 | # http://www.sphinx-doc.org/en/master/config
8 |
9 | # -- Path setup --------------------------------------------------------------
10 |
11 | # If extensions (or modules to document with autodoc) are in another directory,
12 | # add these directories to sys.path here. If the directory is relative to the
13 | # documentation root, use os.path.abspath to make it absolute, like shown here.
14 | #
15 | import os
16 | import sys
17 | import sphinx_rtd_theme
18 | # sys.path.insert(0, os.path.abspath('.'))
19 | sys.path.insert(0, '../gatepy')
20 |
21 |
22 |
23 | # -- Project information -----------------------------------------------------
24 |
25 | project = 'gatepy'
26 | copyright = '2018, draks'
27 | author = 'draks'
28 |
29 | # The short X.Y version
30 | version = ''
31 | # The full version, including alpha/beta/rc tags
32 | release = '0.1'
33 |
34 |
35 | # -- General configuration ---------------------------------------------------
36 |
37 | # If your documentation needs a minimal Sphinx version, state it here.
38 | #
39 | # needs_sphinx = '1.0'
40 |
41 | # Add any Sphinx extension module names here, as strings. They can be
42 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
43 | # ones.
44 | extensions = [
45 | 'sphinx.ext.autodoc',
46 | 'sphinx.ext.napoleon',
47 | ]
48 |
49 | # Add any paths that contain templates here, relative to this directory.
50 | templates_path = ['_templates']
51 |
52 | # The suffix(es) of source filenames.
53 | # You can specify multiple suffix as a list of string:
54 | #
55 | # source_suffix = ['.rst', '.md']
56 | source_suffix = '.rst'
57 |
58 | # The master toctree document.
59 | master_doc = 'index'
60 |
61 | # The language for content autogenerated by Sphinx. Refer to documentation
62 | # for a list of supported languages.
63 | #
64 | # This is also used if you do content translation via gettext catalogs.
65 | # Usually you set "language" from the command line for these cases.
66 | language = None
67 |
68 | # List of patterns, relative to source directory, that match files and
69 | # directories to ignore when looking for source files.
70 | # This pattern also affects html_static_path and html_extra_path .
71 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
72 |
73 | # The name of the Pygments (syntax highlighting) style to use.
74 | pygments_style = 'sphinx'
75 |
76 |
77 | # -- Options for HTML output -------------------------------------------------
78 |
79 | # The theme to use for HTML and HTML Help pages. See the documentation for
80 | # a list of builtin themes.
81 | #
82 | html_theme = 'sphinx_rtd_theme'
83 |
84 | # Theme options are theme-specific and customize the look and feel of a theme
85 | # further. For a list of options available for each theme, see the
86 | # documentation.
87 | #
88 | # html_theme_options = {}
89 |
90 | # Add any paths that contain custom static files (such as style sheets) here,
91 | # relative to this directory. They are copied after the builtin static files,
92 | # so a file named "default.css" will overwrite the builtin "default.css".
93 | html_static_path = ['_static']
94 | html_theme_path = ['_themes', ]
95 |
96 | # Custom sidebar templates, must be a dictionary that maps document names
97 | # to template names.
98 | #
99 | # The default sidebars (for documents that don't match any pattern) are
100 | # defined by theme itself. Builtin themes are using these templates by
101 | # default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
102 | # 'searchbox.html']``.
103 | #
104 | # html_sidebars = {}
105 |
106 |
107 | # -- Options for HTMLHelp output ---------------------------------------------
108 |
109 | # Output file base name for HTML help builder.
110 | htmlhelp_basename = 'gatepydoc'
111 |
112 |
113 | # -- Options for LaTeX output ------------------------------------------------
114 |
115 | latex_elements = {
116 | # The paper size ('letterpaper' or 'a4paper').
117 | #
118 | # 'papersize': 'letterpaper',
119 |
120 | # The font size ('10pt', '11pt' or '12pt').
121 | #
122 | # 'pointsize': '10pt',
123 |
124 | # Additional stuff for the LaTeX preamble.
125 | #
126 | # 'preamble': '',
127 |
128 | # Latex figure (float) alignment
129 | #
130 | # 'figure_align': 'htbp',
131 | }
132 |
133 | # Grouping the document tree into LaTeX files. List of tuples
134 | # (source start file, target name, title,
135 | # author, documentclass [howto, manual, or own class]).
136 | latex_documents = [
137 | (master_doc, 'gatepy.tex', 'gatepy Documentation',
138 | 'draks', 'manual'),
139 | ]
140 |
141 |
142 | # -- Options for manual page output ------------------------------------------
143 |
144 | # One entry per manual page. List of tuples
145 | # (source start file, name, description, authors, manual section).
146 | man_pages = [
147 | (master_doc, 'gatepy', 'gatepy Documentation',
148 | [author], 1)
149 | ]
150 |
151 |
152 | # -- Options for Texinfo output ----------------------------------------------
153 |
154 | # Grouping the document tree into Texinfo files. List of tuples
155 | # (source start file, target name, title, author,
156 | # dir menu entry, description, category)
157 | texinfo_documents = [
158 | (master_doc, 'gatepy', 'gatepy Documentation',
159 | author, 'gatepy', 'One line description of project.',
160 | 'Miscellaneous'),
161 | ]
162 |
163 |
164 | # -- Extension configuration -------------------------------------------------
--------------------------------------------------------------------------------
/docs/index.rst:
--------------------------------------------------------------------------------
1 | .. gatepy documentation master file, created by
2 | sphinx-quickstart on Mon Sep 10 15:00:51 2018.
3 | You can adapt this file completely to your liking, but it should at least
4 | contain the root `toctree` directive.
5 |
6 | Welcome to gatepy's documentation!
7 | ==================================
8 |
9 | .. toctree::
10 | :maxdepth: 2
11 | :caption: Contents:
12 |
13 | reference
14 |
15 |
16 | Indices and tables
17 | ==================
18 |
19 | * :ref:`genindex`
20 | * :ref:`modindex`
21 | * :ref:`search`
22 |
--------------------------------------------------------------------------------
/docs/reference.rst:
--------------------------------------------------------------------------------
1 | the gatepy module reference
2 | ================================
3 |
4 | .. module:: gatepy
5 |
6 | .. autoclass:: FortinetFortiGateMonitor
7 | :members:
8 | :member-order: bysource
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 | # Examples
2 |
3 | This folder will contain example scripts to FortiOS API using only the fortiosapi package, it will not include scripts using the gatepy module.
--------------------------------------------------------------------------------
/examples/_host:
--------------------------------------------------------------------------------
1 | # Host Definition for gatepy
2 |
3 | # Usage:
4 | # source _host
5 |
6 | # FG_HOST can include the port if not using default ports
7 | # like 443 for HTTPS and 80 for HTTP
8 | # Example: '172.16.216.136:10300'
9 |
10 | export FG_HOST='192.168.0.30'
11 | export FG_USER='admin'
12 | export FG_PASS=''
13 |
14 |
--------------------------------------------------------------------------------
/examples/cmdb_antivirus_profile.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure AntiVirus profiles
5 |
6 | Method
7 | https:///api/v2/cmdb/antivirus/profile
8 | https:///api/v2/cmdb/antivirus/profile?filter=name==default
9 |
10 |
11 | CLI
12 | FG # sh antivirus profile default
13 | config antivirus profile
14 | edit "default"
15 | set comment "Scan files and block viruses."
16 | config http
17 | set options scan
18 | end
19 | config ftp
20 | set options scan
21 | end
22 | config imap
23 | set options scan
24 | set executables virus
25 | end
26 | config pop3
27 | set options scan
28 | set executables virus
29 | end
30 | config smtp
31 | set options scan
32 | set executables virus
33 | end
34 | next
35 | end
36 |
37 |
38 | Response
39 | {
40 | "http_method":"GET",
41 | "revision":"1.0.3.9539865665020678008.1535505187",
42 | "results":[
43 | {
44 | "q_origin_key":"default",
45 | "name":"default",
46 | "comment":"Scan files and block viruses.",
47 | "replacemsg-group":"",
48 | "inspection-mode":"flow-based",
49 | "ftgd-analytics":"disable",
50 | "analytics-max-upload":10,
51 | "analytics-wl-filetype":0,
52 | "analytics-bl-filetype":0,
53 | "analytics-db":"disable",
54 | "mobile-malware-db":"enable",
55 | "http":{
56 | "options":"scan",
57 | "archive-block":"",
58 | "archive-log":"",
59 | "emulator":"enable",
60 | "outbreak-prevention":"disabled",
61 | "content-disarm":"disable"
62 | },
63 | "ftp":{
64 | "options":"scan",
65 | "archive-block":"",
66 | "archive-log":"",
67 | "emulator":"enable",
68 | "outbreak-prevention":"disabled"
69 | },
70 | "imap":{
71 | "options":"scan",
72 | "archive-block":"",
73 | "archive-log":"",
74 | "emulator":"enable",
75 | "executables":"virus",
76 | "outbreak-prevention":"disabled",
77 | "content-disarm":"disable"
78 | },
79 | "pop3":{
80 | "options":"scan",
81 | "archive-block":"",
82 | "archive-log":"",
83 | "emulator":"enable",
84 | "executables":"virus",
85 | "outbreak-prevention":"disabled",
86 | "content-disarm":"disable"
87 | },
88 | "smtp":{
89 | "options":"scan",
90 | "archive-block":"",
91 | "archive-log":"",
92 | "emulator":"enable",
93 | "executables":"virus",
94 | "outbreak-prevention":"disabled",
95 | "content-disarm":"disable"
96 | },
97 | "mapi":{
98 | "options":"",
99 | "archive-block":"",
100 | "archive-log":"",
101 | "emulator":"enable",
102 | "executables":"default",
103 | "outbreak-prevention":"disabled"
104 | },
105 | "nntp":{
106 | "options":"",
107 | "archive-block":"",
108 | "archive-log":"",
109 | "emulator":"enable",
110 | "outbreak-prevention":"disabled"
111 | },
112 | "smb":{
113 | "options":"",
114 | "archive-block":"",
115 | "archive-log":"",
116 | "emulator":"enable",
117 | "outbreak-prevention":"disabled"
118 | },
119 | "nac-quar":{
120 | "infected":"none",
121 | "expiry":"5m",
122 | "log":"disable"
123 | },
124 | "content-disarm":{
125 | "original-file-destination":"discard",
126 | "office-macro":"enable",
127 | "office-hylink":"enable",
128 | "office-linked":"enable",
129 | "office-embed":"enable",
130 | "pdf-javacode":"enable",
131 | "pdf-embedfile":"enable",
132 | "pdf-hyperlink":"enable",
133 | "pdf-act-gotor":"enable",
134 | "pdf-act-launch":"enable",
135 | "pdf-act-sound":"enable",
136 | "pdf-act-movie":"enable",
137 | "pdf-act-java":"enable",
138 | "pdf-act-form":"enable",
139 | "cover-page":"enable",
140 | "detect-only":"disable"
141 | },
142 | "av-virus-log":"enable",
143 | "av-block-log":"enable",
144 | "extended-log":"disable",
145 | "scan-mode":"full"
146 | }
147 | ],
148 | "vdom":"root",
149 | "path":"antivirus",
150 | "name":"profile",
151 | "status":"success",
152 | "http_status":200,
153 | "serial":"FGVM020000000000",
154 | "version":"v6.0.0",
155 | "build":76
156 | }
157 |
158 | '''
159 |
160 | from fortiosapi import FortiOSAPI
161 | from pprint import pprint
162 |
163 | fgt = FortiOSAPI()
164 |
165 | device = {
166 | 'host': '10.99.236.231',
167 | 'username': 'admin',
168 | 'password': '',
169 | }
170 |
171 | fgt.login(**device)
172 |
173 | profile_name = 'default'
174 | filter = 'filter=name==' + profile_name
175 |
176 | out = fgt.get('antivirus', 'profile', parameters=filter)
177 |
178 | pprint(out)
179 |
180 |
181 | fgt.logout()
182 |
183 |
--------------------------------------------------------------------------------
/examples/cmdb_firewall_address-add_address.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure IPv4 addresses.
5 |
6 | Method
7 | https:///api/v2/cmdb/firewall/address
8 |
9 |
10 | CLI
11 | FG # sh firewall address example_host
12 | config firewall address
13 | edit "example_host"
14 | set uuid 39673efe-abeb-51e8-a8da-d9052c368d9f
15 | set subnet 192.0.2.1 255.255.255.255
16 | next
17 | end
18 |
19 |
20 | Response
21 | {
22 | "http_method": "GET",
23 | "revision": "31.0.92.9539865665020678008.1535505187",
24 | "results": [
25 | {
26 | "q_origin_key": "example_host",
27 | "name": "example_host",
28 | "uuid": "39673efe-abeb-51e8-a8da-d9052c368d9f",
29 | "subnet": "192.0.2.1 255.255.255.255",
30 | "type": "ipmask",
31 | "start-ip": "192.0.2.1",
32 | "end-ip": "255.255.255.255",
33 | "fqdn": "",
34 | "country": "",
35 | "wildcard-fqdn": "",
36 | "cache-ttl": 0,
37 | "wildcard": "192.0.2.1 255.255.255.255",
38 | "sdn": "",
39 | "tenant": "",
40 | "organization": "",
41 | "epg-name": "",
42 | "subnet-name": "",
43 | "sdn-tag": "",
44 | "policy-group": "",
45 | "comment": "",
46 | "visibility": "enable",
47 | "associated-interface": "",
48 | "color": 0,
49 | "filter": "",
50 | "obj-id": 0,
51 | "list": [],
52 | "tagging": [],
53 | "allow-routing": "disable"
54 | }
55 | ],
56 | "vdom": "root",
57 | "path": "firewall",
58 | "name": "address",
59 | "status": "success",
60 | "http_status": 200,
61 | "serial": "FGVM020000000000",
62 | "version": "v6.0.0",
63 | "build": 76
64 | }
65 | '''
66 |
67 | from fortiosapi import FortiOSAPI
68 | from pprint import pprint
69 |
70 | fgt = FortiOSAPI()
71 |
72 | device = {
73 | 'host': '10.99.236.231',
74 | 'username': 'admin',
75 | 'password': '',
76 | }
77 |
78 | fgt.login(**device)
79 |
80 |
81 | address = {
82 | "name": "test_net_2",
83 | "subnet": "198.51.100.0 255.255.255.0"
84 | }
85 |
86 | # Config address
87 | fgt.set('firewall', 'address', data=address)
88 |
89 | # Check
90 | out = fgt.get('firewall', 'address')
91 |
92 | # Print all address names
93 | for address in out['results']:
94 | print(address['name'])
95 |
96 | fgt.logout()
97 |
--------------------------------------------------------------------------------
/examples/cmdb_firewall_address.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure IPv4 addresses.
5 |
6 | Method
7 | https:///api/v2/cmdb/firewall/address?filter=name==example_host
8 |
9 |
10 | CLI
11 | FG # sh firewall address example_host
12 | config firewall address
13 | edit "example_host"
14 | set uuid 39673efe-abeb-51e8-a8da-d9052c368d9f
15 | set subnet 192.0.2.1 255.255.255.255
16 | next
17 | end
18 |
19 |
20 | Response
21 | {
22 | "http_method": "GET",
23 | "revision": "31.0.92.9539865665020678008.1535505187",
24 | "results": [
25 | {
26 | "q_origin_key": "example_host",
27 | "name": "example_host",
28 | "uuid": "39673efe-abeb-51e8-a8da-d9052c368d9f",
29 | "subnet": "192.0.2.1 255.255.255.255",
30 | "type": "ipmask",
31 | "start-ip": "192.0.2.1",
32 | "end-ip": "255.255.255.255",
33 | "fqdn": "",
34 | "country": "",
35 | "wildcard-fqdn": "",
36 | "cache-ttl": 0,
37 | "wildcard": "192.0.2.1 255.255.255.255",
38 | "sdn": "",
39 | "tenant": "",
40 | "organization": "",
41 | "epg-name": "",
42 | "subnet-name": "",
43 | "sdn-tag": "",
44 | "policy-group": "",
45 | "comment": "",
46 | "visibility": "enable",
47 | "associated-interface": "",
48 | "color": 0,
49 | "filter": "",
50 | "obj-id": 0,
51 | "list": [],
52 | "tagging": [],
53 | "allow-routing": "disable"
54 | }
55 | ],
56 | "vdom": "root",
57 | "path": "firewall",
58 | "name": "address",
59 | "status": "success",
60 | "http_status": 200,
61 | "serial": "FGVM020000000000",
62 | "version": "v6.0.0",
63 | "build": 76
64 | }
65 | '''
66 |
67 | from fortiosapi import FortiOSAPI
68 | from pprint import pprint
69 |
70 | fgt = FortiOSAPI()
71 |
72 | device = {
73 | 'host': '10.99.236.231',
74 | 'username': 'admin',
75 | 'password': '',
76 | }
77 |
78 | fgt.login(**device)
79 |
80 | address_name = 'example_host'
81 | filter = 'filter=name==' + address_name
82 |
83 | out = fgt.get('firewall', 'address', parameters=filter)
84 |
85 | pprint(out)
86 |
87 | fgt.logout()
88 |
--------------------------------------------------------------------------------
/examples/cmdb_firewall_addrgrp-add_addrgrp.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure IPv4 address groups.
5 |
6 | Method
7 | https:///api/v2/cmdb/firewall/addrgrp
8 |
9 |
10 | CLI
11 | FG # sh firewall addrgrp
12 | config firewall addrgrp
13 | edit "add_grp_example"
14 | set uuid 1802a868-abee-51e8-fb7b-cde25eb10edd
15 | set member "example_host" "test_net_2"
16 | next
17 | end
18 |
19 |
20 | Response
21 | {
22 | "http_method": "GET",
23 | "revision": "5.0.94.9539865665020678008.1535505187",
24 | "results": [
25 | {
26 | "q_origin_key": "add_grp_example",
27 | "name": "add_grp_example",
28 | "uuid": "1802a868-abee-51e8-fb7b-cde25eb10edd",
29 | "member": [
30 | {
31 | "q_origin_key": "example_host",
32 | "name": "example_host"
33 | },
34 | {
35 | "q_origin_key": "test_net_2",
36 | "name": "test_net_2"
37 | }
38 | ],
39 | "comment": "",
40 | "visibility": "enable",
41 | "color": 0,
42 | "tagging": [],
43 | "allow-routing": "disable"
44 | }
45 | ],
46 | "vdom": "root",
47 | "path": "firewall",
48 | "name": "addrgrp",
49 | "status": "success",
50 | "http_status": 200,
51 | "serial": "FGVM020000000000",
52 | "version": "v6.0.0",
53 | "build": 76
54 | }
55 | '''
56 |
57 | from fortiosapi import FortiOSAPI
58 | from pprint import pprint
59 |
60 | fgt = FortiOSAPI()
61 |
62 | device = {
63 | 'host': '10.99.236.231',
64 | 'username': 'admin',
65 | 'password': '',
66 | }
67 |
68 | fgt.login(**device)
69 |
70 | out = fgt.get('firewall', 'addrgrp')
71 |
72 |
73 |
74 | address_group = {
75 | "name": "test_group_1",
76 | "member": [
77 | {"name": "test_net_1"},
78 | {"name": "test_net_2"},
79 | ]
80 | }
81 |
82 | # Config address
83 | fgt.set('firewall', 'addrgrp', data=address_group)
84 |
85 | # Check
86 | out = fgt.get('firewall', 'addrgrp')
87 |
88 | pprint(out)
89 |
90 | fgt.logout()
91 |
--------------------------------------------------------------------------------
/examples/cmdb_firewall_addrgrp.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure IPv4 address groups.
5 |
6 | Method
7 | https:///api/v2/cmdb/firewall/addrgrp
8 |
9 |
10 | CLI
11 | FG # sh firewall addrgrp
12 | config firewall addrgrp
13 | edit "add_grp_example"
14 | set uuid 1802a868-abee-51e8-fb7b-cde25eb10edd
15 | set member "example_host" "test_net_2"
16 | next
17 | end
18 |
19 |
20 | Response
21 | {
22 | "http_method": "GET",
23 | "revision": "5.0.94.9539865665020678008.1535505187",
24 | "results": [
25 | {
26 | "q_origin_key": "add_grp_example",
27 | "name": "add_grp_example",
28 | "uuid": "1802a868-abee-51e8-fb7b-cde25eb10edd",
29 | "member": [
30 | {
31 | "q_origin_key": "example_host",
32 | "name": "example_host"
33 | },
34 | {
35 | "q_origin_key": "test_net_2",
36 | "name": "test_net_2"
37 | }
38 | ],
39 | "comment": "",
40 | "visibility": "enable",
41 | "color": 0,
42 | "tagging": [],
43 | "allow-routing": "disable"
44 | }
45 | ],
46 | "vdom": "root",
47 | "path": "firewall",
48 | "name": "addrgrp",
49 | "status": "success",
50 | "http_status": 200,
51 | "serial": "FGVM020000000000",
52 | "version": "v6.0.0",
53 | "build": 76
54 | }
55 | '''
56 |
57 | from fortiosapi import FortiOSAPI
58 | from pprint import pprint
59 |
60 | fgt = FortiOSAPI()
61 |
62 | device = {
63 | 'host': '10.99.236.231',
64 | 'username': 'admin',
65 | 'password': '',
66 | }
67 |
68 | fgt.login(**device)
69 |
70 | out = fgt.get('firewall', 'addrgrp')
71 |
72 | pprint(out)
73 |
74 | fgt.logout()
75 |
--------------------------------------------------------------------------------
/examples/cmdb_firewall_policy-add_policy.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure IPv4 policies
5 |
6 | Method
7 | https:///api/v2/cmdb/firewall/policy?action=schema
8 | https:///api/v2/cmdb/firewall/policy
9 |
10 |
11 | CLI
12 | FG # sh firewall policy
13 | config firewall policy
14 | edit 1
15 | set name "to Internet"
16 | set uuid bfa5cd8e-aba3-51e8-567b-302f11df04b7
17 | set srcintf "port1"
18 | set dstintf "port2"
19 | set srcaddr "all"
20 | set dstaddr "all"
21 | set action accept
22 | set schedule "always"
23 | set service "ALL"
24 | set logtraffic all
25 | set nat enable
26 | next
27 | end
28 |
29 |
30 | Response
31 | {
32 | "http_method": "GET",
33 | "revision": "20.0.0.9539865665020678008.1535505187",
34 | "results": [
35 | {
36 | "q_origin_key": 1,
37 | "policyid": 1,
38 | "name": "to Internet",
39 | "uuid": "bfa5cd8e-aba3-51e8-567b-302f11df04b7",
40 | "srcintf": [
41 | {
42 | "q_origin_key": "port1",
43 | "name": "port1"
44 | }
45 | ],
46 | "dstintf": [
47 | {
48 | "q_origin_key": "port2",
49 | "name": "port2"
50 | }
51 | ],
52 | "srcaddr": [
53 | {
54 | "q_origin_key": "all",
55 | "name": "all"
56 | }
57 | ],
58 | "dstaddr": [
59 | {
60 | "q_origin_key": "all",
61 | "name": "all"
62 | }
63 | ],
64 | "internet-service": "disable",
65 | "internet-service-id": [],
66 | "internet-service-custom": [],
67 | "internet-service-src": "disable",
68 | "internet-service-src-id": [],
69 | "internet-service-src-custom": [],
70 | "rtp-nat": "disable",
71 | "rtp-addr": [],
72 | "learning-mode": "disable",
73 | "action": "accept",
74 | "send-deny-packet": "disable",
75 | "firewall-session-dirty": "check-all",
76 | "status": "enable",
77 | "schedule": "always",
78 | "schedule-timeout": "disable",
79 | "service": [
80 | {
81 | "q_origin_key": "ALL",
82 | "name": "ALL"
83 | }
84 | ],
85 | "dscp-match": "disable",
86 | "dscp-negate": "disable",
87 | "dscp-value": "000000",
88 | "tcp-session-without-syn": "disable",
89 | "utm-status": "disable",
90 | "profile-type": "single",
91 | "profile-group": "",
92 | "av-profile": "",
93 | "webfilter-profile": "",
94 | "dnsfilter-profile": "",
95 | "spamfilter-profile": "",
96 | "dlp-sensor": "",
97 | "ips-sensor": "",
98 | "application-list": "",
99 | "voip-profile": "",
100 | "icap-profile": "",
101 | "waf-profile": "",
102 | "ssh-filter-profile": "",
103 | "profile-protocol-options": "",
104 | "ssl-ssh-profile": "",
105 | "logtraffic": "all",
106 | "logtraffic-start": "disable",
107 | "capture-packet": "disable",
108 | "wanopt": "disable",
109 | "wanopt-detection": "active",
110 | "wanopt-passive-opt": "default",
111 | "wanopt-profile": "",
112 | "wanopt-peer": "",
113 | "webcache": "disable",
114 | "webcache-https": "disable",
115 | "traffic-shaper": "",
116 | "traffic-shaper-reverse": "",
117 | "per-ip-shaper": "",
118 | "application": [],
119 | "app-category": [],
120 | "url-category": [],
121 | "app-group": [],
122 | "nat": "enable",
123 | "permit-any-host": "disable",
124 | "permit-stun-host": "disable",
125 | "fixedport": "disable",
126 | "ippool": "disable",
127 | "poolname": [],
128 | "session-ttl": 0,
129 | "vlan-cos-fwd": 255,
130 | "vlan-cos-rev": 255,
131 | "inbound": "disable",
132 | "outbound": "enable",
133 | "natinbound": "disable",
134 | "natoutbound": "disable",
135 | "wccp": "disable",
136 | "ntlm": "disable",
137 | "ntlm-guest": "disable",
138 | "ntlm-enabled-browsers": [],
139 | "fsso": "enable",
140 | "wsso": "enable",
141 | "rsso": "disable",
142 | "fsso-agent-for-ntlm": "",
143 | "groups": [],
144 | "users": [],
145 | "devices": [],
146 | "auth-path": "disable",
147 | "disclaimer": "disable",
148 | "vpntunnel": "",
149 | "natip": "0.0.0.0 0.0.0.0",
150 | "match-vip": "disable",
151 | "diffserv-forward": "disable",
152 | "diffserv-reverse": "disable",
153 | "diffservcode-forward": "000000",
154 | "diffservcode-rev": "000000",
155 | "tcp-mss-sender": 0,
156 | "tcp-mss-receiver": 0,
157 | "comments": "",
158 | "label": "",
159 | "global-label": "",
160 | "auth-cert": "",
161 | "auth-redirect-addr": "",
162 | "redirect-url": "",
163 | "identity-based-route": "",
164 | "block-notification": "disable",
165 | "custom-log-fields": [],
166 | "replacemsg-override-group": "",
167 | "srcaddr-negate": "disable",
168 | "dstaddr-negate": "disable",
169 | "service-negate": "disable",
170 | "internet-service-negate": "disable",
171 | "internet-service-src-negate": "disable",
172 | "timeout-send-rst": "disable",
173 | "captive-portal-exempt": "disable",
174 | "ssl-mirror": "disable",
175 | "ssl-mirror-intf": [],
176 | "scan-botnet-connections": "disable",
177 | "dsri": "disable",
178 | "radius-mac-auth-bypass": "disable",
179 | "delay-tcp-npu-session": "disable",
180 | "vlan-filter": ""
181 | }
182 | ],
183 | "vdom": "root",
184 | "path": "firewall",
185 | "name": "policy",
186 | "status": "success",
187 | "http_status": 200,
188 | "serial": "FGVM020000000000",
189 | "version": "v6.0.0",
190 | "build": 76
191 | }
192 | '''
193 |
194 | from fortiosapi import FortiOSAPI
195 | from pprint import pprint
196 |
197 | fgt = FortiOSAPI()
198 |
199 | device = {
200 | 'host': '10.99.236.231',
201 | 'username': 'admin',
202 | 'password': '',
203 | }
204 |
205 | fgt.login(**device)
206 |
207 |
208 | # 'policyid': '0' will use the next available id
209 | rule = {
210 | 'policyid': '0',
211 | 'name': 'port1 to port2 - API',
212 | 'action': 'accept',
213 | 'srcintf': [{'name': 'port1'}],
214 | 'dstintf': [{'name': 'port2'}],
215 | 'srcaddr': [{'name': 'all'}],
216 | 'dstaddr': [{'name': 'all'}],
217 | 'schedule': 'always',
218 | 'service': [{'name': 'HTTPS'}],
219 | 'logtraffic': 'all',
220 | }
221 |
222 | # Config rule
223 | fgt.set('firewall', 'policy', data=rule)
224 |
225 | # Check
226 | out = fgt.get('firewall', 'policy')
227 |
228 | # Print all rule names
229 | for rule in out['results']:
230 | print(rule['name'])
231 |
232 | fgt.logout()
233 |
--------------------------------------------------------------------------------
/examples/cmdb_firewall_policy.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure IPv4 policies
5 |
6 | Method
7 | https:///api/v2/cmdb/firewall/policy?action=schema
8 | https:///api/v2/cmdb/firewall/policy
9 |
10 |
11 | CLI
12 | FG # sh firewall policy
13 | config firewall policy
14 | edit 1
15 | set name "to Internet"
16 | set uuid bfa5cd8e-aba3-51e8-567b-302f11df04b7
17 | set srcintf "port1"
18 | set dstintf "port2"
19 | set srcaddr "all"
20 | set dstaddr "all"
21 | set action accept
22 | set schedule "always"
23 | set service "ALL"
24 | set logtraffic all
25 | set nat enable
26 | next
27 | end
28 |
29 |
30 | Response
31 | {
32 | "http_method": "GET",
33 | "revision": "20.0.0.9539865665020678008.1535505187",
34 | "results": [
35 | {
36 | "q_origin_key": 1,
37 | "policyid": 1,
38 | "name": "to Internet",
39 | "uuid": "bfa5cd8e-aba3-51e8-567b-302f11df04b7",
40 | "srcintf": [
41 | {
42 | "q_origin_key": "port1",
43 | "name": "port1"
44 | }
45 | ],
46 | "dstintf": [
47 | {
48 | "q_origin_key": "port2",
49 | "name": "port2"
50 | }
51 | ],
52 | "srcaddr": [
53 | {
54 | "q_origin_key": "all",
55 | "name": "all"
56 | }
57 | ],
58 | "dstaddr": [
59 | {
60 | "q_origin_key": "all",
61 | "name": "all"
62 | }
63 | ],
64 | "internet-service": "disable",
65 | "internet-service-id": [],
66 | "internet-service-custom": [],
67 | "internet-service-src": "disable",
68 | "internet-service-src-id": [],
69 | "internet-service-src-custom": [],
70 | "rtp-nat": "disable",
71 | "rtp-addr": [],
72 | "learning-mode": "disable",
73 | "action": "accept",
74 | "send-deny-packet": "disable",
75 | "firewall-session-dirty": "check-all",
76 | "status": "enable",
77 | "schedule": "always",
78 | "schedule-timeout": "disable",
79 | "service": [
80 | {
81 | "q_origin_key": "ALL",
82 | "name": "ALL"
83 | }
84 | ],
85 | "dscp-match": "disable",
86 | "dscp-negate": "disable",
87 | "dscp-value": "000000",
88 | "tcp-session-without-syn": "disable",
89 | "utm-status": "disable",
90 | "profile-type": "single",
91 | "profile-group": "",
92 | "av-profile": "",
93 | "webfilter-profile": "",
94 | "dnsfilter-profile": "",
95 | "spamfilter-profile": "",
96 | "dlp-sensor": "",
97 | "ips-sensor": "",
98 | "application-list": "",
99 | "voip-profile": "",
100 | "icap-profile": "",
101 | "waf-profile": "",
102 | "ssh-filter-profile": "",
103 | "profile-protocol-options": "",
104 | "ssl-ssh-profile": "",
105 | "logtraffic": "all",
106 | "logtraffic-start": "disable",
107 | "capture-packet": "disable",
108 | "wanopt": "disable",
109 | "wanopt-detection": "active",
110 | "wanopt-passive-opt": "default",
111 | "wanopt-profile": "",
112 | "wanopt-peer": "",
113 | "webcache": "disable",
114 | "webcache-https": "disable",
115 | "traffic-shaper": "",
116 | "traffic-shaper-reverse": "",
117 | "per-ip-shaper": "",
118 | "application": [],
119 | "app-category": [],
120 | "url-category": [],
121 | "app-group": [],
122 | "nat": "enable",
123 | "permit-any-host": "disable",
124 | "permit-stun-host": "disable",
125 | "fixedport": "disable",
126 | "ippool": "disable",
127 | "poolname": [],
128 | "session-ttl": 0,
129 | "vlan-cos-fwd": 255,
130 | "vlan-cos-rev": 255,
131 | "inbound": "disable",
132 | "outbound": "enable",
133 | "natinbound": "disable",
134 | "natoutbound": "disable",
135 | "wccp": "disable",
136 | "ntlm": "disable",
137 | "ntlm-guest": "disable",
138 | "ntlm-enabled-browsers": [],
139 | "fsso": "enable",
140 | "wsso": "enable",
141 | "rsso": "disable",
142 | "fsso-agent-for-ntlm": "",
143 | "groups": [],
144 | "users": [],
145 | "devices": [],
146 | "auth-path": "disable",
147 | "disclaimer": "disable",
148 | "vpntunnel": "",
149 | "natip": "0.0.0.0 0.0.0.0",
150 | "match-vip": "disable",
151 | "diffserv-forward": "disable",
152 | "diffserv-reverse": "disable",
153 | "diffservcode-forward": "000000",
154 | "diffservcode-rev": "000000",
155 | "tcp-mss-sender": 0,
156 | "tcp-mss-receiver": 0,
157 | "comments": "",
158 | "label": "",
159 | "global-label": "",
160 | "auth-cert": "",
161 | "auth-redirect-addr": "",
162 | "redirect-url": "",
163 | "identity-based-route": "",
164 | "block-notification": "disable",
165 | "custom-log-fields": [],
166 | "replacemsg-override-group": "",
167 | "srcaddr-negate": "disable",
168 | "dstaddr-negate": "disable",
169 | "service-negate": "disable",
170 | "internet-service-negate": "disable",
171 | "internet-service-src-negate": "disable",
172 | "timeout-send-rst": "disable",
173 | "captive-portal-exempt": "disable",
174 | "ssl-mirror": "disable",
175 | "ssl-mirror-intf": [],
176 | "scan-botnet-connections": "disable",
177 | "dsri": "disable",
178 | "radius-mac-auth-bypass": "disable",
179 | "delay-tcp-npu-session": "disable",
180 | "vlan-filter": ""
181 | }
182 | ],
183 | "vdom": "root",
184 | "path": "firewall",
185 | "name": "policy",
186 | "status": "success",
187 | "http_status": 200,
188 | "serial": "FGVM020000000000",
189 | "version": "v6.0.0",
190 | "build": 76
191 | }
192 | '''
193 |
194 | from fortiosapi import FortiOSAPI
195 | from pprint import pprint
196 |
197 | fgt = FortiOSAPI()
198 |
199 | device = {
200 | 'host': '10.99.236.231',
201 | 'username': 'admin',
202 | 'password': '',
203 | }
204 |
205 | fgt.login(**device)
206 |
207 | out = fgt.get('firewall', 'policy')
208 |
209 | pprint(out)
210 |
211 | fgt.logout()
212 |
--------------------------------------------------------------------------------
/examples/cmdb_system_global-configure.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure global attributes.
5 |
6 |
7 | Method
8 | https:///api/v2/cmdb/system/global
9 |
10 |
11 | CLI
12 | FG # sh sys gl
13 | config system global
14 | set alias "FG"
15 | set hostname "FG"
16 | set timezone 04
17 | end
18 |
19 |
20 | Response
21 | NA
22 | '''
23 |
24 | import os
25 | from fortiosapi import FortiOSAPI
26 |
27 | FG = FortiOSAPI()
28 |
29 | # Source _host
30 | FG_HOST = os.environ['FG_HOST']
31 | FG_USER = os.environ['FG_USER']
32 | FG_PASS = os.environ['FG_PASS']
33 |
34 | DEVICE = {
35 | 'host': FG_HOST,
36 | 'username': FG_USER,
37 | 'password': FG_PASS,
38 | }
39 |
40 | FG.login(**DEVICE)
41 |
42 |
43 | global_config = {
44 | 'hostname': 'FG_new',
45 | 'timezone': "18",
46 | 'gui-theme': 'melongene'
47 | }
48 |
49 | # Config
50 | FG.set('system', 'global', data=global_config)
51 |
52 | # Check
53 | out = FG.get('system', 'global')
54 |
55 | get_hostname = out['results']['hostname']
56 | get_timezone = out['results']['timezone']
57 | get_gui_theme = out['results']['gui-theme']
58 |
59 | print()
60 | print('{:13}{}'.format('Hostname:', get_hostname))
61 | print('{:13}{}'.format('Time Zone:', get_timezone))
62 | print('{:13}{}'.format('GUI Theme:', get_gui_theme))
63 | print()
64 |
65 | FG.logout()
66 |
--------------------------------------------------------------------------------
/examples/cmdb_system_global.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure global attributes.
5 |
6 |
7 | Method
8 | https:///api/v2/cmdb/system/global
9 |
10 |
11 | CLI
12 | FG # sh sys gl
13 | config system global
14 | set alias "FG"
15 | set hostname "FG"
16 | set timezone 04
17 | end
18 |
19 |
20 | Response
21 | {
22 | "http_method": "GET",
23 | "revision": "6.0.0.9542928822994478097.1536278864",
24 | "results": {
25 | "language": "english",
26 | "gui-ipv6": "disable",
27 | "gui-certificates": "enable",
28 | "gui-custom-language": "disable",
29 | "gui-wireless-opensecurity": "disable",
30 | "gui-display-hostname": "disable",
31 | "gui-lines-per-page": 50,
32 | "admin-https-ssl-versions": "tlsv1-1 tlsv1-2",
33 | "admintimeout": 5,
34 | "admin-console-timeout": 0,
35 | "admin-concurrent": "enable",
36 | "admin-lockout-threshold": 3,
37 | "admin-lockout-duration": 60,
38 | "refresh": 0,
39 | "interval": 5,
40 | "failtime": 5,
41 | "daily-restart": "disable",
42 | "restart-time": "00:00",
43 | "radius-port": 1812,
44 | "admin-login-max": 100,
45 | "remoteauthtimeout": 5,
46 | "ldapconntimeout": 500,
47 | "batch-cmdb": "enable",
48 | "multi-factor-authentication": "optional",
49 | "ssl-min-proto-version": "TLSv1-2",
50 | "dst": "enable",
51 | "timezone": "04",
52 | "traffic-priority": "tos",
53 | "traffic-priority-level": "medium",
54 | "anti-replay": "strict",
55 | "send-pmtu-icmp": "enable",
56 | "honor-df": "enable",
57 | "revision-image-auto-backup": "disable",
58 | "revision-backup-on-logout": "disable",
59 | "management-vdom": "root",
60 | "hostname": "FG",
61 | "alias": "FG",
62 | "strong-crypto": "enable",
63 | "ssh-cbc-cipher": "enable",
64 | "ssh-hmac-md5": "enable",
65 | "ssh-kex-sha1": "enable",
66 | "ssl-static-key-ciphers": "enable",
67 | "snat-route-change": "disable",
68 | "cli-audit-log": "disable",
69 | "dh-params": "2048",
70 | "fds-statistics": "enable",
71 | "fds-statistics-period": 60,
72 | "multicast-forward": "enable",
73 | "mc-ttl-notchange": "disable",
74 | "asymroute": "disable",
75 | "tcp-option": "enable",
76 | "lldp-transmission": "disable",
77 | "proxy-auth-timeout": 10,
78 | "proxy-re-authentication-mode": "session",
79 | "proxy-auth-lifetime": "disable",
80 | "proxy-auth-lifetime-timeout": 480,
81 | "sys-perf-log-interval": 5,
82 | "check-protocol-header": "loose",
83 | "vip-arp-range": "restricted",
84 | "reset-sessionless-tcp": "disable",
85 | "allow-traffic-redirect": "enable",
86 | "strict-dirty-session-check": "enable",
87 | "tcp-halfclose-timer": 120,
88 | "tcp-halfopen-timer": 10,
89 | "tcp-timewait-timer": 1,
90 | "udp-idle-timer": 180,
91 | "block-session-timer": 30,
92 | "ip-src-port-range": "1024-25000",
93 | "pre-login-banner": "disable",
94 | "post-login-banner": "disable",
95 | "tftp": "enable",
96 | "av-failopen": "pass",
97 | "av-failopen-session": "disable",
98 | "memory-use-threshold-extreme": 95,
99 | "memory-use-threshold-red": 88,
100 | "memory-use-threshold-green": 82,
101 | "cpu-use-threshold": 90,
102 | "check-reset-range": "disable",
103 | "vdom-admin": "disable",
104 | "long-vdom-name": "disable",
105 | "admin-port": 80,
106 | "admin-sport": 443,
107 | "admin-https-redirect": "enable",
108 | "admin-ssh-password": "enable",
109 | "admin-restrict-local": "disable",
110 | "admin-ssh-port": 22,
111 | "admin-ssh-grace-time": 120,
112 | "admin-ssh-v1": "disable",
113 | "admin-telnet-port": 23,
114 | "admin-maintainer": "enable",
115 | "admin-server-cert": "self-sign",
116 | "user-server-cert": "Fortinet_Factory",
117 | "admin-https-pki-required": "disable",
118 | "wifi-certificate": "Fortinet_Wifi",
119 | "wifi-ca-certificate": "Fortinet_Wifi_CA",
120 | "auth-http-port": 1000,
121 | "auth-https-port": 1003,
122 | "auth-keepalive": "disable",
123 | "policy-auth-concurrent": 0,
124 | "auth-session-limit": "block-new",
125 | "auth-cert": "Fortinet_Factory",
126 | "clt-cert-req": "disable",
127 | "fortiservice-port": 8013,
128 | "endpoint-control-portal-port": 8009,
129 | "endpoint-control-fds-access": "enable",
130 | "tp-mc-skip-policy": "disable",
131 | "cfg-save": "automatic",
132 | "cfg-revert-timeout": 600,
133 | "reboot-upon-config-restore": "enable",
134 | "admin-scp": "disable",
135 | "security-rating-result-submission": "enable",
136 | "security-rating-run-on-schedule": "enable",
137 | "wireless-controller": "enable",
138 | "wireless-controller-port": 5246,
139 | "fortiextender-data-port": 25246,
140 | "fortiextender": "disable",
141 | "fortiextender-vlan-mode": "disable",
142 | "switch-controller": "disable",
143 | "switch-controller-reserved-network": "169.254.0.0 255.255.0.0",
144 | "proxy-worker-count": 0,
145 | "scanunit-count": 0,
146 | "proxy-kxp-hardware-acceleration": "enable",
147 | "proxy-cipher-hardware-acceleration": "enable",
148 | "fgd-alert-subscription": "",
149 | "ipsec-hmac-offload": "enable",
150 | "ipv6-accept-dad": 1,
151 | "ipv6-allow-anycast-probe": "disable",
152 | "csr-ca-attribute": "enable",
153 | "wimax-4g-usb": "disable",
154 | "cert-chain-max": 8,
155 | "sslvpn-max-worker-count": 0,
156 | "sslvpn-kxp-hardware-acceleration": "enable",
157 | "sslvpn-cipher-hardware-acceleration": "enable",
158 | "sslvpn-plugin-version-check": "enable",
159 | "two-factor-ftk-expiry": 60,
160 | "two-factor-email-expiry": 60,
161 | "two-factor-sms-expiry": 60,
162 | "two-factor-fac-expiry": 60,
163 | "two-factor-ftm-expiry": 72,
164 | "per-user-bwl": "disable",
165 | "virtual-server-count": 0,
166 | "virtual-server-hardware-acceleration": "enable",
167 | "wad-worker-count": 0,
168 | "wad-csvc-cs-count": 1,
169 | "wad-csvc-db-count": 0,
170 | "wad-source-affinity": "enable",
171 | "login-timestamp": "disable",
172 | "miglogd-children": 0,
173 | "special-file-23-support": "disable",
174 | "log-uuid": "policy-only",
175 | "log-ssl-connection": "disable",
176 | "arp-max-entry": 131072,
177 | "av-affinity": "0",
178 | "wad-affinity": "0",
179 | "ips-affinity": "0",
180 | "miglog-affinity": "0",
181 | "ndp-max-entry": 0,
182 | "br-fdb-max-entry": 8192,
183 | "max-route-cache-size": 0,
184 | "ipsec-asic-offload": "enable",
185 | "ipsec-soft-dec-async": "disable",
186 | "device-idle-timeout": 300,
187 | "device-identification-active-scan-delay": 90,
188 | "compliance-check": "enable",
189 | "compliance-check-time": "00:00:00",
190 | "gui-device-latitude": "",
191 | "gui-device-longitude": "",
192 | "private-data-encryption": "disable",
193 | "auto-auth-extension-device": "enable",
194 | "gui-theme": "green",
195 | "gui-date-format": "yyyy/MM/dd",
196 | "igmp-state-limit": 3200
197 | },
198 | "vdom": "root",
199 | "path": "system",
200 | "name": "global",
201 | "status": "success",
202 | "http_status": 200,
203 | "serial": "FGVM040000000000",
204 | "version": "v6.0.2",
205 | "build": 163
206 | }
207 | '''
208 |
209 | import os
210 | from pprint import pprint
211 | from fortiosapi import FortiOSAPI
212 |
213 | FG = FortiOSAPI()
214 |
215 | # Source _host
216 | FG_HOST = os.environ['FG_HOST']
217 | FG_USER = os.environ['FG_USER']
218 | FG_PASS = os.environ['FG_PASS']
219 |
220 | DEVICE = {
221 | 'host': FG_HOST,
222 | 'username': FG_USER,
223 | 'password': FG_PASS,
224 | }
225 |
226 | FG.login(**DEVICE)
227 |
228 |
229 |
230 | out = FG.get('system', 'global')
231 |
232 | pprint(out)
233 |
234 | FG.logout()
235 |
--------------------------------------------------------------------------------
/examples/cmdb_system_interface-check_required_fields.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure interfaces.
5 |
6 | Method
7 | https:///api/v2/cmdb/system/interface?action=schema
8 |
9 |
10 | CLI
11 | FG # sh sys int port1
12 | config system interface
13 | edit "port1"
14 | set vdom "root"
15 | set ip 192.168.0.1 255.255.255.0
16 | set allowaccess ping https ssh http fgfm
17 | set type physical
18 | set snmp-index 1
19 | next
20 | end
21 |
22 |
23 | Response
24 | NA
25 | '''
26 |
27 | from fortiosapi import FortiOSAPI
28 | from pprint import pprint
29 |
30 | fgt = FortiOSAPI()
31 |
32 | device = {
33 | 'host': '10.99.236.231',
34 | 'username': 'admin',
35 | 'password': '',
36 | }
37 |
38 | fgt.login(**device)
39 |
40 |
41 | schema = 'action=schema'
42 |
43 | out = fgt.get('system', 'interface', parameters=schema)
44 |
45 | interface_table = out['results']['children']
46 |
47 | for field, value in interface_table.items():
48 | if value.get('required'):
49 | print()
50 | print(field, value)
51 |
52 | fgt.logout()
53 |
--------------------------------------------------------------------------------
/examples/cmdb_system_interface-configure.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure interfaces.
5 |
6 | Method
7 | https:///api/v2/cmdb/system/interface
8 |
9 |
10 | CLI
11 |
12 | FG # conf sys int
13 | FG (interface) # ed port3
14 | FG (port3) # set ip 192.0.2.200/24
15 | FG (port3) # set allowaccess ping
16 | FG (port3) # end
17 |
18 | FG # sh sys int port3
19 | config system interface
20 | edit "port3"
21 | set vdom "root"
22 | set ip 192.0.2.200 255.255.255.0
23 | set allowaccess ping
24 | set type physical
25 | set snmp-index 3
26 | next
27 | end
28 |
29 |
30 | Response
31 | NA
32 | '''
33 |
34 | import os
35 | from pprint import pprint
36 | from fortiosapi import FortiOSAPI
37 |
38 | FG = FortiOSAPI()
39 |
40 | # Source _host
41 | FG_HOST = os.environ['FG_HOST']
42 | FG_USER = os.environ['FG_USER']
43 | FG_PASS = os.environ['FG_PASS']
44 |
45 | DEVICE = {
46 | 'host': FG_HOST,
47 | 'username': FG_USER,
48 | 'password': FG_PASS,
49 | }
50 |
51 | FG.login(**DEVICE)
52 |
53 | interface_name = 'port3'
54 |
55 | interface_config = {
56 | 'name': interface_name,
57 | 'vdom': 'root',
58 | "ip": "192.0.2.200 255.255.255.0",
59 | "allowaccess": "ping",
60 | }
61 |
62 | # Config
63 | FG.set('system', 'interface', data=interface_config)
64 |
65 | # Check
66 | filter = 'filter=name==' + interface_name
67 | out = FG.get('system', 'interface', parameters=filter)
68 |
69 | pprint(out)
70 |
71 | FG.logout()
72 |
--------------------------------------------------------------------------------
/examples/cmdb_system_interface.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure interfaces.
5 |
6 | Method
7 | https:///api/v2/cmdb/system/interface?filter=name==port1
8 |
9 |
10 | CLI
11 | FG # sh sys int port1
12 | config system interface
13 | edit "port1"
14 | set vdom "root"
15 | set ip 192.168.0.1 255.255.255.0
16 | set allowaccess ping https ssh http fgfm
17 | set type physical
18 | set snmp-index 1
19 | next
20 | end
21 |
22 |
23 | Response
24 | {
25 | "http_method": "GET",
26 | "revision": "23.0.50.9539865665020678008.1535505187",
27 | "results": [
28 | {
29 | "q_origin_key": "port1",
30 | "name": "port1",
31 | "vdom": "root",
32 | "vrf": 0,
33 | "cli-conn-status": 0,
34 | "fortilink": "disable",
35 | "mode": "static",
36 | "distance": 5,
37 | "priority": 0,
38 | "dhcp-relay-service": "disable",
39 | "dhcp-relay-ip": "",
40 | "dhcp-relay-type": "regular",
41 | "dhcp-relay-agent-option": "enable",
42 | "management-ip": "0.0.0.0 0.0.0.0",
43 | "ip": "192.168.0.1 255.255.255.0",
44 | "allowaccess": "ping https ssh http fgfm",
45 | "gwdetect": "disable",
46 | "ping-serv-status": 0,
47 | "detectserver": "",
48 | "detectprotocol": "ping",
49 | "ha-priority": 1,
50 | "fail-detect": "disable",
51 | "fail-detect-option": "link-down",
52 | "fail-alert-method": "link-down",
53 | "fail-action-on-extender": "soft-restart",
54 | "fail-alert-interfaces": [],
55 | "dhcp-client-identifier": "",
56 | "dhcp-renew-time": 0,
57 | "ipunnumbered": "0.0.0.0",
58 | "username": "",
59 | "pppoe-unnumbered-negotiate": "enable",
60 | "password": "",
61 | "idle-timeout": 0,
62 | "detected-peer-mtu": 0,
63 | "disc-retry-timeout": 1,
64 | "padt-retry-timeout": 1,
65 | "service-name": "",
66 | "ac-name": "",
67 | "lcp-echo-interval": 5,
68 | "lcp-max-echo-fails": 3,
69 | "defaultgw": "enable",
70 | "dns-server-override": "enable",
71 | "auth-type": "auto",
72 | "pptp-client": "disable",
73 | "pptp-user": "",
74 | "pptp-password": "",
75 | "pptp-server-ip": "0.0.0.0",
76 | "pptp-auth-type": "auto",
77 | "pptp-timeout": 0,
78 | "arpforward": "enable",
79 | "ndiscforward": "enable",
80 | "broadcast-forward": "disable",
81 | "bfd": "global",
82 | "bfd-desired-min-tx": 250,
83 | "bfd-detect-mult": 3,
84 | "bfd-required-min-rx": 250,
85 | "l2forward": "disable",
86 | "icmp-redirect": "enable",
87 | "vlanforward": "disable",
88 | "stpforward": "disable",
89 | "stpforward-mode": "rpl-all-ext-id",
90 | "ips-sniffer-mode": "disable",
91 | "ident-accept": "disable",
92 | "ipmac": "disable",
93 | "subst": "disable",
94 | "macaddr": "00:50:56:01:68:fc",
95 | "substitute-dst-mac": "00:00:00:00:00:00",
96 | "speed": "auto",
97 | "status": "up",
98 | "netbios-forward": "disable",
99 | "wins-ip": "0.0.0.0",
100 | "type": "physical",
101 | "dedicated-to": "none",
102 | "trust-ip-1": "0.0.0.0 0.0.0.0",
103 | "trust-ip-2": "0.0.0.0 0.0.0.0",
104 | "trust-ip-3": "0.0.0.0 0.0.0.0",
105 | "trust-ip6-1": "::/0",
106 | "trust-ip6-2": "::/0",
107 | "trust-ip6-3": "::/0",
108 | "mtu-override": "disable",
109 | "mtu": 1500,
110 | "wccp": "disable",
111 | "netflow-sampler": "disable",
112 | "sflow-sampler": "disable",
113 | "drop-overlapped-fragment": "disable",
114 | "drop-fragment": "disable",
115 | "scan-botnet-connections": "disable",
116 | "src-check": "enable",
117 | "sample-rate": 2000,
118 | "polling-interval": 20,
119 | "sample-direction": "both",
120 | "explicit-web-proxy": "disable",
121 | "explicit-ftp-proxy": "disable",
122 | "proxy-captive-portal": "disable",
123 | "tcp-mss": 0,
124 | "inbandwidth": 0,
125 | "outbandwidth": 0,
126 | "egress-shaping-profile": "",
127 | "disconnect-threshold": 0,
128 | "spillover-threshold": 0,
129 | "ingress-spillover-threshold": 0,
130 | "weight": 0,
131 | "interface": "",
132 | "external": "disable",
133 | "vlanid": 0,
134 | "forward-domain": 0,
135 | "remote-ip": "0.0.0.0 0.0.0.0",
136 | "member": [],
137 | "lacp-mode": "active",
138 | "lacp-ha-slave": "enable",
139 | "lacp-speed": "slow",
140 | "min-links": 1,
141 | "min-links-down": "operational",
142 | "algorithm": "L4",
143 | "link-up-delay": 50,
144 | "priority-override": "enable",
145 | "aggregate": "",
146 | "redundant-interface": "",
147 | "managed-device": [],
148 | "devindex": 3,
149 | "vindex": 0,
150 | "switch": "",
151 | "description": "",
152 | "alias": "",
153 | "security-mode": "none",
154 | "captive-portal": 0,
155 | "security-mac-auth-bypass": "disable",
156 | "security-external-web": "",
157 | "security-external-logout": "",
158 | "replacemsg-override-group": "",
159 | "security-redirect-url": "",
160 | "security-exempt-list": "",
161 | "security-groups": [],
162 | "device-identification": "disable",
163 | "device-user-identification": "enable",
164 | "device-identification-active-scan": "disable",
165 | "device-access-list": "",
166 | "lldp-transmission": "vdom",
167 | "fortiheartbeat": "disable",
168 | "broadcast-forticlient-discovery": "disable",
169 | "endpoint-compliance": "disable",
170 | "estimated-upstream-bandwidth": 0,
171 | "estimated-downstream-bandwidth": 0,
172 | "vrrp-virtual-mac": "disable",
173 | "vrrp": [],
174 | "role": "undefined",
175 | "snmp-index": 1,
176 | "secondary-IP": "disable",
177 | "secondaryip": [],
178 | "preserve-session-route": "disable",
179 | "auto-auth-extension-device": "disable",
180 | "ap-discover": "enable",
181 | "fortilink-stacking": "enable",
182 | "fortilink-split-interface": "disable",
183 | "internal": 0,
184 | "fortilink-backup-link": 0,
185 | "switch-controller-access-vlan": "disable",
186 | "switch-controller-igmp-snooping": "disable",
187 | "switch-controller-dhcp-snooping": "disable",
188 | "switch-controller-dhcp-snooping-verify-mac": "disable",
189 | "switch-controller-dhcp-snooping-option82": "disable",
190 | "switch-controller-arp-inspection": "disable",
191 | "switch-controller-learning-limit": 0,
192 | "color": 0,
193 | "tagging": [],
194 | "ipv6": {
195 | "ip6-mode": "static",
196 | "nd-mode": "basic",
197 | "nd-cert": "",
198 | "nd-security-level": 0,
199 | "nd-timestamp-delta": 300,
200 | "nd-timestamp-fuzz": 1,
201 | "nd-cga-modifier": "0065636473612D776974682D73686132",
202 | "ip6-dns-server-override": "enable",
203 | "ip6-address": "::/0",
204 | "ip6-extra-addr": [],
205 | "ip6-allowaccess": "",
206 | "ip6-send-adv": "disable",
207 | "ip6-manage-flag": "disable",
208 | "ip6-other-flag": "disable",
209 | "ip6-max-interval": 600,
210 | "ip6-min-interval": 198,
211 | "ip6-link-mtu": 0,
212 | "ip6-reachable-time": 0,
213 | "ip6-retrans-time": 0,
214 | "ip6-default-life": 1800,
215 | "ip6-hop-limit": 0,
216 | "autoconf": "disable",
217 | "ip6-upstream-interface": "",
218 | "ip6-subnet": "::/0",
219 | "ip6-prefix-list": [],
220 | "ip6-delegated-prefix-list": [],
221 | "dhcp6-relay-service": "disable",
222 | "dhcp6-relay-type": "regular",
223 | "dhcp6-relay-ip": "",
224 | "dhcp6-client-options": "",
225 | "dhcp6-prefix-delegation": "disable",
226 | "dhcp6-information-request": "disable",
227 | "dhcp6-prefix-hint": "::/0",
228 | "dhcp6-prefix-hint-plt": 604800,
229 | "dhcp6-prefix-hint-vlt": 2592000,
230 | "vrrp-virtual-mac6": "disable",
231 | "vrip6_link_local": "::",
232 | "vrrp6": []
233 | }
234 | }
235 | ],
236 | "vdom": "root",
237 | "path": "system",
238 | "name": "interface",
239 | "status": "success",
240 | "http_status": 200,
241 | "serial": "FGVM020000000000",
242 | "version": "v6.0.0",
243 | "build": 76
244 | }
245 | '''
246 |
247 | import os
248 | from pprint import pprint
249 | from fortiosapi import FortiOSAPI
250 |
251 | FG = FortiOSAPI()
252 |
253 | # Source _host
254 | FG_HOST = os.environ['FG_HOST']
255 | FG_USER = os.environ['FG_USER']
256 | FG_PASS = os.environ['FG_PASS']
257 |
258 | DEVICE = {
259 | 'host': FG_HOST,
260 | 'username': FG_USER,
261 | 'password': FG_PASS,
262 | }
263 |
264 | FG.login(**DEVICE)
265 |
266 |
267 | interface_name = 'port1'
268 | filter = 'filter=name==' + interface_name
269 |
270 | out = FG.get('system', 'interface', parameters=filter)
271 |
272 | pprint(out)
273 |
274 | FG.logout()
275 |
--------------------------------------------------------------------------------
/examples/cmdb_user_local-add_user.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure local users.
5 |
6 | Method
7 | https:///api/v2/cmdb/user/local
8 |
9 |
10 | CLI
11 | FG # config user local
12 | FG (local) # ed user1
13 | FG (user1) # set type password
14 | FG (user1) # set passwd user1pwd
15 | FG (user1) # end
16 |
17 | FG # sh user local user1
18 | config user local
19 | edit "user1"
20 | set type password
21 | set passwd-time 2018-08-31 06:19:37
22 | set passwd ENC xxx
23 | next
24 | end
25 |
26 |
27 | Response
28 | NA
29 | '''
30 |
31 | import os
32 | from pprint import pprint
33 | from fortiosapi import FortiOSAPI
34 |
35 | FG = FortiOSAPI()
36 |
37 | # Source _host
38 | FG_HOST = os.environ['FG_HOST']
39 | FG_USER = os.environ['FG_USER']
40 | FG_PASS = os.environ['FG_PASS']
41 |
42 | DEVICE = {
43 | 'host': FG_HOST,
44 | 'username': FG_USER,
45 | 'password': FG_PASS,
46 | }
47 |
48 | FG.login(**DEVICE)
49 |
50 | user_config = {
51 | 'name': 'user1',
52 | 'type': 'password',
53 | "passwd": 'user1pwd',
54 | }
55 |
56 | # Config
57 | FG.set('user', 'local', data=user_config)
58 |
59 | # Check
60 | filter = 'filter=name==' + user_config['name']
61 | out = FG.get('user', 'local', parameters=filter)
62 |
63 | pprint(out)
64 |
65 | FG.logout()
66 |
--------------------------------------------------------------------------------
/examples/cmdb_user_local.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure local users.
5 |
6 | Method
7 | https:///api/v2/cmdb/user/local
8 |
9 |
10 | CLI
11 | FG # sh user local
12 | config user local
13 | edit "user1"
14 | set type password
15 | set passwd-time 2018-08-31 06:19:37
16 | set passwd ENC xxx
17 | next
18 | end
19 |
20 |
21 | Response
22 | {
23 | "http_method": "GET",
24 | "revision": "3.0.0.9539865665020678008.1535658219",
25 | "results": [
26 | {
27 | "q_origin_key": "user1",
28 | "name": "user1",
29 | "id": 2164260865,
30 | "status": "enable",
31 | "type": "password",
32 | "passwd": "ENC XXXX",
33 | "ldap-server": "",
34 | "radius-server": "",
35 | "tacacs+-server": "",
36 | "two-factor": "disable",
37 | "fortitoken": "",
38 | "email-to": "",
39 | "sms-server": "fortiguard",
40 | "sms-custom-server": "",
41 | "sms-phone": "",
42 | "passwd-policy": "",
43 | "passwd-time": "2018-08-31 06:11:22",
44 | "authtimeout": 0,
45 | "workstation": "",
46 | "auth-concurrent-override": "disable",
47 | "auth-concurrent-value": 0,
48 | "ppk-secret": "",
49 | "ppk-identity": ""
50 | }
51 | ],
52 | "vdom": "root",
53 | "path": "user",
54 | "name": "local",
55 | "status": "success",
56 | "http_status": 200,
57 | "serial": "FGVM020000119895",
58 | "version": "v6.0.1",
59 | "build": 131
60 | }
61 | '''
62 |
63 | import os
64 | from pprint import pprint
65 | from fortiosapi import FortiOSAPI
66 |
67 | FG = FortiOSAPI()
68 |
69 | # Source _host
70 | FG_HOST = os.environ['FG_HOST']
71 | FG_USER = os.environ['FG_USER']
72 | FG_PASS = os.environ['FG_PASS']
73 |
74 | DEVICE = {
75 | 'host': FG_HOST,
76 | 'username': FG_USER,
77 | 'password': FG_PASS,
78 | }
79 |
80 | FG.login(**DEVICE)
81 |
82 | out = FG.get('user', 'local')
83 |
84 | pprint(out)
85 |
86 | FG.logout()
87 |
--------------------------------------------------------------------------------
/examples/cmdb_vpn.ssl_settings-configure.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure SSL VPN.
5 |
6 |
7 | Method
8 | https:///api/v2/cmdb/vpn.ssl/settings
9 |
10 |
11 | CLI
12 | FG # conf vpn ssl settings
13 | FG (settings) # set tunnel-ip-pools SSLVPN_TUNNEL_ADDR1
14 | FG (settings) # set port 10443
15 | FG (settings) # set source-interface port1
16 | FG (settings) # set source-address all
17 | FG (settings) # set default-portal full-access
18 | FG (settings) # end
19 |
20 | FG # sh vpn ssl settings
21 | config vpn ssl settings
22 | set servercert "self-sign"
23 | set tunnel-ip-pools "SSLVPN_TUNNEL_ADDR1"
24 | set source-interface "port1"
25 | set source-address "all"
26 | set default-portal "full-access"
27 | end
28 |
29 |
30 | Response
31 | NA
32 | '''
33 |
34 | import os
35 | from pprint import pprint
36 | from fortiosapi import FortiOSAPI
37 |
38 | FG = FortiOSAPI()
39 |
40 | # Source _host
41 | FG_HOST = os.environ['FG_HOST']
42 | FG_USER = os.environ['FG_USER']
43 | FG_PASS = os.environ['FG_PASS']
44 |
45 | DEVICE = {
46 | 'host': FG_HOST,
47 | 'username': FG_USER,
48 | 'password': FG_PASS,
49 | }
50 |
51 | FG.login(**DEVICE)
52 |
53 | vpnssl_settings = {
54 | 'servercert':'self-sign',
55 | 'tunnel-ip-pools':[{'name':'SSLVPN_TUNNEL_ADDR1'}],
56 | 'source-interface':[{'name':'port1'}],
57 | 'source-address':[{'name':'all'}],
58 | 'port':'10443',
59 | 'default-portal':'full-access',
60 | }
61 |
62 |
63 | # Config
64 | FG.set('vpn.ssl', 'settings', data=vpnssl_settings)
65 |
66 | # Check
67 | out = FG.get('vpn.ssl', 'settings')
68 |
69 | pprint(out)
70 |
71 | FG.logout()
72 |
--------------------------------------------------------------------------------
/examples/cmdb_vpn.ssl_settings.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Configure SSL VPN.
5 |
6 |
7 | Method
8 | https:///api/v2/cmdb/vpn.ssl/settings
9 |
10 |
11 | CLI
12 | FG # sh vpn ssl settings
13 | config vpn ssl settings
14 | set servercert "self-sign"
15 | set tunnel-ip-pools "SSLVPN_TUNNEL_ADDR1"
16 | set source-interface "port1"
17 | set source-address "all"
18 | set default-portal "full-access"
19 | end
20 |
21 |
22 | Response
23 | {
24 | "http_method": "GET",
25 | "revision": "15.0.0.9539865665020678008.1535658219",
26 | "results": {
27 | "reqclientcert": "disable",
28 | "tlsv1-0": "disable",
29 | "tlsv1-1": "enable",
30 | "tlsv1-2": "enable",
31 | "banned-cipher": "",
32 | "ssl-insert-empty-fragment": "enable",
33 | "https-redirect": "disable",
34 | "x-content-type-options": "enable",
35 | "ssl-client-renegotiation": "disable",
36 | "force-two-factor-auth": "disable",
37 | "unsafe-legacy-renegotiation": "disable",
38 | "servercert": "self-sign",
39 | "algorithm": "high",
40 | "idle-timeout": 300,
41 | "auth-timeout": 28800,
42 | "login-attempt-limit": 2,
43 | "login-block-time": 60,
44 | "login-timeout": 30,
45 | "dtls-hello-timeout": 10,
46 | "tunnel-ip-pools": [
47 | {
48 | "q_origin_key": "SSLVPN_TUNNEL_ADDR1",
49 | "name": "SSLVPN_TUNNEL_ADDR1"
50 | }
51 | ],
52 | "tunnel-ipv6-pools": [],
53 | "dns-suffix": "",
54 | "dns-server1": "0.0.0.0",
55 | "dns-server2": "0.0.0.0",
56 | "wins-server1": "0.0.0.0",
57 | "wins-server2": "0.0.0.0",
58 | "ipv6-dns-server1": "::",
59 | "ipv6-dns-server2": "::",
60 | "ipv6-wins-server1": "::",
61 | "ipv6-wins-server2": "::",
62 | "url-obscuration": "disable",
63 | "http-compression": "disable",
64 | "http-only-cookie": "enable",
65 | "deflate-compression-level": 6,
66 | "deflate-min-data-size": 300,
67 | "port": 10443,
68 | "port-precedence": "enable",
69 | "auto-tunnel-static-route": "enable",
70 | "header-x-forwarded-for": "add",
71 | "source-interface": [
72 | {
73 | "q_origin_key": "port1",
74 | "name": "port1"
75 | }
76 | ],
77 | "source-address": [
78 | {
79 | "q_origin_key": "all",
80 | "name": "all"
81 | }
82 | ],
83 | "source-address-negate": "disable",
84 | "source-address6": [],
85 | "source-address6-negate": "disable",
86 | "default-portal": "full-access",
87 | "authentication-rule": [],
88 | "dtls-tunnel": "enable",
89 | "check-referer": "disable",
90 | "http-request-header-timeout": 20,
91 | "http-request-body-timeout": 30
92 | },
93 | "vdom": "root",
94 | "path": "vpn.ssl",
95 | "name": "settings",
96 | "status": "success",
97 | "http_status": 200,
98 | "serial": "FGVM020000119895",
99 | "version": "v6.0.1",
100 | "build": 131
101 | }
102 | '''
103 |
104 | import os
105 | from pprint import pprint
106 | from fortiosapi import FortiOSAPI
107 |
108 | FG = FortiOSAPI()
109 |
110 | # Source _host
111 | FG_HOST = os.environ['FG_HOST']
112 | FG_USER = os.environ['FG_USER']
113 | FG_PASS = os.environ['FG_PASS']
114 |
115 | DEVICE = {
116 | 'host': FG_HOST,
117 | 'username': FG_USER,
118 | 'password': FG_PASS,
119 | }
120 |
121 | FG.login(**DEVICE)
122 |
123 | out = FG.get('vpn.ssl', 'settings')
124 |
125 | pprint(out)
126 |
127 | FG.logout()
128 |
--------------------------------------------------------------------------------
/examples/monitor_firewall_policy-check_last_used.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | List traffic statistics for IPv4 policies.
5 |
6 | Method
7 | https:///api/v2/monitor/firewall/policy
8 |
9 | # PolicyID 0 means 'Implicit Deny' rule
10 |
11 | CLI
12 | FG # diag firewall iprope show 00100004 13
13 | idx=13 pkts/bytes=553936822/569261079433 asic_pkts/asic_bytes=373877794/400601238192 nturbo_pkts/nturbo_bytes=236116365/236482516860 flag=0x0 hit count:12467662
14 | first:2018-03-21 18:40:50 last:2018-08-29 18:21:06
15 | established session count:1347
16 | first est:2018-03-21 18:40:50 last est:2018-08-29 18:21:05
17 |
18 |
19 | Response FGVM
20 | {
21 | "http_method":"GET",
22 | "results":[
23 | {
24 | "policyid":0,
25 | "active_sessions":0,
26 | "bytes":0,
27 | "packets":0
28 | },
29 | {
30 | "policyid":1,
31 | "uuid":"bfa5cd8e-aba3-51e8-567b-302f11df04b7",
32 | "active_sessions":0,
33 | "bytes":0,
34 | "packets":0
35 | },
36 | {
37 | "policyid":66,
38 | "uuid":"88c14218-abbb-51e8-4fb5-4edfbd13d043",
39 | "active_sessions":0,
40 | "bytes":0,
41 | "packets":0
42 | },
43 | {
44 | "policyid":3,
45 | "uuid":"e8047652-abbe-51e8-0273-ef4a243c29c5",
46 | "active_sessions":0,
47 | "bytes":0,
48 | "packets":0
49 | }
50 | ],
51 | "vdom":"root",
52 | "path":"firewall",
53 | "name":"policy",
54 | "status":"success",
55 | "serial":"FGVM020000000000",
56 | "version":"v6.0.0",
57 | "build":76
58 | }
59 |
60 |
61 | Response FG-81E
62 | {
63 | "http_method":"GET",
64 | "results":[
65 | {
66 | "policyid":0,
67 | "active_sessions":0,
68 | "bytes":536085,
69 | "packets":8397,
70 | "software_bytes":536085,
71 | "software_packets":8397,
72 | "asic_bytes":0,
73 | "asic_packets":0,
74 | "nturbo_bytes":0,
75 | "nturbo_packets":0,
76 | "last_used":1535478216,
77 | "first_used":1521670953,
78 | "hit_count":10770
79 | },
80 | {
81 | "policyid":1,
82 | "uuid":"bdd7cf24-f7fe-51e7-de6c-f42e21b200d1",
83 | "active_sessions":0,
84 | "bytes":0,
85 | "packets":0,
86 | "software_bytes":0,
87 | "software_packets":0,
88 | "asic_bytes":0,
89 | "asic_packets":0,
90 | "nturbo_bytes":0,
91 | "nturbo_packets":0
92 | },
93 | {
94 | "policyid":13,
95 | "uuid":"d61723ce-2c41-51e8-214e-3ca194c65c79",
96 | "active_sessions":2056,
97 | "bytes":569238562854,
98 | "packets":553910965,
99 | "software_bytes":168657862523,
100 | "software_packets":180048782,
101 | "asic_bytes":164098194283,
102 | "asic_packets":137745885,
103 | "nturbo_bytes":236482506048,
104 | "nturbo_packets":236116298,
105 | "last_used":1535577206,
106 | "first_used":1521668450,
107 | "hit_count":12463107,
108 | "session_last_used":1535577206,
109 | "session_first_used":1521668450,
110 | "session_count":2043
111 | }
112 | ],
113 | "vdom":"root",
114 | "path":"firewall",
115 | "name":"policy",
116 | "status":"success",
117 | "serial":"FG81EP0000000000",
118 | "version":"v6.0.2",
119 | "build":163
120 | }
121 | '''
122 |
123 | from fortiosapi import FortiOSAPI
124 | from pprint import pprint
125 | import time
126 |
127 | fgt = FortiOSAPI()
128 |
129 | device = {
130 | 'host': '10.99.236.231',
131 | 'username': 'admin',
132 | 'password': '',
133 | }
134 |
135 | fgt.login(**device)
136 |
137 | out = fgt.monitor('firewall', 'policy')
138 |
139 | for policy in out['results']:
140 | policyid = str(policy['policyid'])
141 | if 'last_used' not in policy:
142 | print('Policy ID {:10} {:^38}'.format(policyid, '** Never Used **'))
143 | else:
144 | policy_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(policy['last_used']))
145 | print('Policy ID {:10} Last Used on: {} GMT'.format(policyid, policy_time))
146 |
147 | fgt.logout()
148 |
--------------------------------------------------------------------------------
/examples/monitor_firewall_policy-lookup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Performs a policy lookup by creating a dummy packet and asking the kernel which policy would be hit.
5 |
6 |
7 | Method
8 | https:///api/v2/monitor/firewall/policy-lookup?srcintf=port2&sourceip=1.1.1.1&protocol=6&dest=10.0.0.10&destport=80
9 |
10 |
11 | CLI
12 | NA
13 |
14 |
15 | Response
16 | {
17 | "http_method": "GET",
18 | "results": {
19 | "destip": "10.0.0.10",
20 | "policy_id": 2, # policy_id 0 here means implicit deny
21 | "success": true
22 | },
23 | "vdom": "root",
24 | "path": "firewall",
25 | "name": "policy-lookup",
26 | "status": "success",
27 | "serial": "FGVM040000141945",
28 | "version": "v6.0.2",
29 | "build": 163
30 | }
31 | '''
32 |
33 | import os
34 | from pprint import pprint
35 | from fortiosapi import FortiOSAPI
36 |
37 | FG = FortiOSAPI()
38 |
39 | # Source _host
40 | FG_HOST = os.environ['FG_HOST']
41 | FG_USER = os.environ['FG_USER']
42 | FG_PASS = os.environ['FG_PASS']
43 |
44 | DEVICE = {
45 | 'host': FG_HOST,
46 | 'username': FG_USER,
47 | 'password': FG_PASS,
48 | }
49 |
50 | FG.login(**DEVICE)
51 |
52 | # Protocol Numbers
53 | # https://www.iana.org/assignments/protocol-numbers/protocol-numbers.txt
54 |
55 | param = {
56 | 'srcintf': 'port2',
57 | 'sourceip': '1.1.1.1',
58 | 'protocol': '6',
59 | 'dest': '10.0.0.10',
60 | 'destport': 80,
61 | }
62 |
63 | out = FG.monitor('firewall', 'policy-lookup', parameters=param)
64 |
65 | pprint(out)
66 |
67 | FG.logout()
68 |
--------------------------------------------------------------------------------
/examples/monitor_firewall_policy.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | List traffic statistics for IPv4 policies.
5 |
6 | Method
7 | https:///api/v2/monitor/firewall/policy
8 |
9 | # PolicyID 0 means 'Implicit Deny' rule
10 |
11 | CLI
12 | FG # diag firewall iprope show 00100004 13
13 | idx=13 pkts/bytes=553936822/569261079433 asic_pkts/asic_bytes=373877794/400601238192 nturbo_pkts/nturbo_bytes=236116365/236482516860 flag=0x0 hit count:12467662
14 | first:2018-03-21 18:40:50 last:2018-08-29 18:21:06
15 | established session count:1347
16 | first est:2018-03-21 18:40:50 last est:2018-08-29 18:21:05
17 |
18 |
19 | Response FGVM
20 | {
21 | "http_method":"GET",
22 | "results":[
23 | {
24 | "policyid":0,
25 | "active_sessions":0,
26 | "bytes":0,
27 | "packets":0
28 | },
29 | {
30 | "policyid":1,
31 | "uuid":"bfa5cd8e-aba3-51e8-567b-302f11df04b7",
32 | "active_sessions":0,
33 | "bytes":0,
34 | "packets":0
35 | },
36 | {
37 | "policyid":66,
38 | "uuid":"88c14218-abbb-51e8-4fb5-4edfbd13d043",
39 | "active_sessions":0,
40 | "bytes":0,
41 | "packets":0
42 | },
43 | {
44 | "policyid":3,
45 | "uuid":"e8047652-abbe-51e8-0273-ef4a243c29c5",
46 | "active_sessions":0,
47 | "bytes":0,
48 | "packets":0
49 | }
50 | ],
51 | "vdom":"root",
52 | "path":"firewall",
53 | "name":"policy",
54 | "status":"success",
55 | "serial":"FGVM020000000000",
56 | "version":"v6.0.0",
57 | "build":76
58 | }
59 |
60 |
61 | Response FG-81E
62 | {
63 | "http_method":"GET",
64 | "results":[
65 | {
66 | "policyid":0,
67 | "active_sessions":0,
68 | "bytes":536085,
69 | "packets":8397,
70 | "software_bytes":536085,
71 | "software_packets":8397,
72 | "asic_bytes":0,
73 | "asic_packets":0,
74 | "nturbo_bytes":0,
75 | "nturbo_packets":0,
76 | "last_used":1535478216,
77 | "first_used":1521670953,
78 | "hit_count":10770
79 | },
80 | {
81 | "policyid":1,
82 | "uuid":"bdd7cf24-f7fe-51e7-de6c-f42e21b200d1",
83 | "active_sessions":0,
84 | "bytes":0,
85 | "packets":0,
86 | "software_bytes":0,
87 | "software_packets":0,
88 | "asic_bytes":0,
89 | "asic_packets":0,
90 | "nturbo_bytes":0,
91 | "nturbo_packets":0
92 | },
93 | {
94 | "policyid":13,
95 | "uuid":"d61723ce-2c41-51e8-214e-3ca194c65c79",
96 | "active_sessions":2056,
97 | "bytes":569238562854,
98 | "packets":553910965,
99 | "software_bytes":168657862523,
100 | "software_packets":180048782,
101 | "asic_bytes":164098194283,
102 | "asic_packets":137745885,
103 | "nturbo_bytes":236482506048,
104 | "nturbo_packets":236116298,
105 | "last_used":1535577206,
106 | "first_used":1521668450,
107 | "hit_count":12463107,
108 | "session_last_used":1535577206,
109 | "session_first_used":1521668450,
110 | "session_count":2043
111 | }
112 | ],
113 | "vdom":"root",
114 | "path":"firewall",
115 | "name":"policy",
116 | "status":"success",
117 | "serial":"FG81EP0000000000",
118 | "version":"v6.0.2",
119 | "build":163
120 | }
121 | '''
122 |
123 | from fortiosapi import FortiOSAPI
124 | from pprint import pprint
125 |
126 | fgt = FortiOSAPI()
127 |
128 | device = {
129 | 'host': '10.99.236.231',
130 | 'username': 'admin',
131 | 'password': '',
132 | }
133 |
134 | fgt.login(**device)
135 |
136 | out = fgt.monitor('firewall', 'policy')
137 |
138 | pprint(out)
139 |
140 | fgt.logout()
141 |
--------------------------------------------------------------------------------
/examples/monitor_license_status.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Get current license & registration status.
5 |
6 | Method
7 | https:///api/v2/monitor/license/status
8 |
9 |
10 | CLI
11 | NA
12 |
13 | JSON
14 | {
15 | "http_method": "GET",
16 | "results": {
17 | "fortiguard": {
18 | "type": "service_or_support",
19 | "connected": false,
20 | "update_server_usa": true
21 | },
22 | "forticare": {
23 | "type": "service_or_support",
24 | "status": "pending"
25 | },
26 | "antivirus": {
27 | "type": "downloaded_fds_object",
28 | "status": "pending",
29 | "version": "1.00000",
30 | "entitlement": "AVDB",
31 | "last_update": 1517440740,
32 | "db_status": "db_type_extended",
33 | "engine": {
34 | "version": "6.00006",
35 | "last_update": 1520984340
36 | }
37 | },
38 | "mobile_malware": {
39 | "type": "downloaded_fds_object",
40 | "status": "pending",
41 | "version": "0.00000",
42 | "entitlement": "FMSS",
43 | "last_update": 978332400
44 | },
45 | "ips": {
46 | "type": "downloaded_fds_object",
47 | "status": "pending",
48 | "version": "6.00741",
49 | "entitlement": "NIDS",
50 | "last_update": 1448962200,
51 | "db_status": "db_type_normal",
52 | "engine": {
53 | "version": "4.00012",
54 | "last_update": 1521870900
55 | },
56 | "malicious_urls": {
57 | "type": "downloaded_fds_object",
58 | "status": "pending",
59 | "version": "1.00001",
60 | "entitlement": "NIDS",
61 | "last_update": 1420099260
62 | }
63 | },
64 | "industrial_db": {
65 | "type": "downloaded_fds_object",
66 | "status": "pending",
67 | "version": "6.00741",
68 | "entitlement": "ISSS",
69 | "last_update": 1448962200
70 | },
71 | "appctrl": {
72 | "type": "downloaded_fds_object",
73 | "status": "pending",
74 | "version": "6.00741",
75 | "entitlement": "FMWR",
76 | "last_update": 1448962200
77 | },
78 | "internet_service_db": {
79 | "type": "downloaded_fds_object",
80 | "status": "licensed",
81 | "version": "2.00662",
82 | "last_update": 1447786560
83 | },
84 | "device_os_id": {
85 | "type": "downloaded_fds_object",
86 | "status": "pending",
87 | "version": "1.00065",
88 | "entitlement": "FMWR",
89 | "last_update": 1522314180
90 | },
91 | "botnet_ip": {
92 | "type": "downloaded_fds_object",
93 | "status": "pending",
94 | "version": "1.00000",
95 | "entitlement": "AVDB",
96 | "last_update": 1338270660
97 | },
98 | "botnet_domain": {
99 | "type": "downloaded_fds_object",
100 | "status": "pending",
101 | "version": "0.00000",
102 | "entitlement": "AVDB",
103 | "last_update": 978332400
104 | },
105 | "security_rating": {
106 | "type": "downloaded_fds_object",
107 | "status": "pending",
108 | "version": "1.00005",
109 | "entitlement": "FGSA",
110 | "last_update": 1519872360
111 | },
112 | "malicious_urls": {
113 | "type": "downloaded_fds_object",
114 | "status": "pending",
115 | "version": "1.00001",
116 | "entitlement": "NIDS",
117 | "last_update": 1420099260
118 | },
119 | "web_filtering": {
120 | "type": "live_fortiguard_service",
121 | "status": "unavailable",
122 | "category_list_version": 8
123 | },
124 | "outbreak_prevention": {
125 | "type": "live_fortiguard_service",
126 | "status": "unavailable"
127 | },
128 | "antispam": {
129 | "type": "live_fortiguard_service",
130 | "status": "unavailable"
131 | },
132 | "forticlient": {
133 | "type": "product_integration",
134 | "status": "free_license",
135 | "can_upgrade": false,
136 | "used": 0,
137 | "max": 10
138 | },
139 | "forticloud": {
140 | "type": "product_integration",
141 | "status": "cloud_logged_out"
142 | },
143 | "vdom": {
144 | "type": "platform",
145 | "can_upgrade": true,
146 | "used": 1,
147 | "max": 1
148 | },
149 | "vm": {
150 | "type": "platform",
151 | "status": "vm_eval",
152 | "license_model": 1,
153 | "license_platform_name": "FGVMEV",
154 | "cpu_used": 1,
155 | "cpu_max": 1,
156 | "mem_used": 1043333120,
157 | "mem_max": 1073741824,
158 | "expires": 1537454850,
159 | "evaluation_mode": true
160 | },
161 | "sms": {
162 | "type": "other",
163 | "status": "pending",
164 | "used": 0,
165 | "max": 0
166 | }
167 | },
168 | "vdom": "root",
169 | "path": "license",
170 | "name": "status",
171 | "status": "success",
172 | "serial": "FGVMEVYEP9DLGG46",
173 | "version": "v6.0.0",
174 | "build": 76
175 | }
176 |
177 | '''
178 |
179 | import os
180 | from pprint import pprint
181 | from fortiosapi import FortiOSAPI
182 |
183 |
184 | fgt = FortiOSAPI()
185 |
186 | # Source _host
187 | FG_HOST = os.environ['FG_HOST']
188 | FG_USER = os.environ['FG_USER']
189 | FG_PASS = os.environ['FG_PASS']
190 |
191 | DEVICE = {
192 | 'host': FG_HOST,
193 | 'username': FG_USER,
194 | 'password': FG_PASS,
195 | }
196 |
197 | fgt.login(**DEVICE)
198 |
199 | out = fgt.monitor('license', 'status')
200 |
201 | pprint(out)
202 |
203 | fgt.logout()
204 |
--------------------------------------------------------------------------------
/examples/monitor_log_device_state.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Retrieve information on state of log devices.
5 |
6 |
7 | Method
8 | https:///api/v2/monitor/log/device/state
9 |
10 |
11 | CLI
12 | NA
13 |
14 |
15 | Response
16 | {
17 | "http_method": "GET",
18 | "results": {
19 | "memory": {
20 | "is_available": true,
21 | "is_enabled": false,
22 | "is_default": false,
23 | "is_ha_supported": true
24 | },
25 | "disk": {
26 | "is_available": true,
27 | "is_enabled": true,
28 | "is_loggable": true,
29 | "num_ssds_available": 1,
30 | "is_fortiview_supported": true,
31 | "disabled_by_default": false,
32 | "is_ha_supported": true
33 | },
34 | "fortianalyzer": {
35 | "is_available": true,
36 | "is_enabled": false
37 | },
38 | "forticloud": {
39 | "is_available": false,
40 | "is_enabled": false
41 | }
42 | },
43 | "vdom": "root",
44 | "path": "log",
45 | "name": "device",
46 | "action": "state",
47 | "status": "success",
48 | "serial": "FGVM020000000000",
49 | "version": "v6.0.1",
50 | "build": 131
51 | }
52 | '''
53 |
54 | import os
55 | from pprint import pprint
56 | from fortiosapi import FortiOSAPI
57 |
58 | FG = FortiOSAPI()
59 |
60 | # Source _host
61 | FG_HOST = os.environ['FG_HOST']
62 | FG_USER = os.environ['FG_USER']
63 | FG_PASS = os.environ['FG_PASS']
64 |
65 | DEVICE = {
66 | 'host': FG_HOST,
67 | 'username': FG_USER,
68 | 'password': FG_PASS,
69 | }
70 |
71 | FG.login(**DEVICE)
72 |
73 | out = FG.monitor('log', 'device/state')
74 |
75 | pprint(out)
76 |
77 | FG.logout()
78 |
--------------------------------------------------------------------------------
/examples/monitor_router_ipv4.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | List all active IPv4 routing table entries
5 |
6 | Method
7 | https:///api/v2/monitor/router/ipv4
8 |
9 | CLI
10 | FG # get router info routing-table all
11 |
12 | Routing table for VRF=0
13 | Codes: K - kernel, C - connected, S - static, R - RIP, B - BGP
14 | O - OSPF, IA - OSPF inter area
15 | N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
16 | E1 - OSPF external type 1, E2 - OSPF external type 2
17 | i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
18 | * - candidate default
19 |
20 | S* 0.0.0.0/0 [10/0] via 192.168.0.254, port1
21 | C 1.1.1.0/24 is directly connected, port2
22 | S 10.0.0.0/8 [10/0] via 192.168.0.254, port1
23 | C 192.168.0.0/24 is directly connected, port1
24 |
25 |
26 | Response
27 | {
28 | "http_method":"GET",
29 | "results":[
30 | {
31 | "ip_version":4,
32 | "type":"static",
33 | "ip_mask":"0.0.0.0\/0",
34 | "distance":10,
35 | "metric":0,
36 | "gateway":"192.168.0.254",
37 | "interface":"port1"
38 | },
39 | {
40 | "ip_version":4,
41 | "type":"connect",
42 | "ip_mask":"1.1.1.0\/24",
43 | "distance":0,
44 | "metric":0,
45 | "gateway":"0.0.0.0",
46 | "interface":"port2"
47 | },
48 | {
49 | "ip_version":4,
50 | "type":"static",
51 | "ip_mask":"10.0.0.0\/8",
52 | "distance":10,
53 | "metric":0,
54 | "gateway":"192.168.0.254",
55 | "interface":"port1"
56 | },
57 | {
58 | "ip_version":4,
59 | "type":"connect",
60 | "ip_mask":"192.168.0.0\/24",
61 | "distance":0,
62 | "metric":0,
63 | "gateway":"0.0.0.0",
64 | "interface":"port1"
65 | }
66 | ],
67 | "vdom":"root",
68 | "path":"router",
69 | "name":"ipv4",
70 | "status":"success",
71 | "serial":"FGVM020000000000",
72 | "version":"v6.0.0",
73 | "build":76
74 | }
75 | '''
76 |
77 | from fortiosapi import FortiOSAPI
78 | from pprint import pprint
79 |
80 | fgt = FortiOSAPI()
81 |
82 | device = {
83 | 'host': '10.99.236.231',
84 | 'username': 'admin',
85 | 'password': '',
86 | }
87 |
88 | fgt.login(**device)
89 |
90 | out = fgt.monitor('router', 'ipv4')
91 |
92 | pprint(out)
93 |
94 | fgt.logout()
95 |
--------------------------------------------------------------------------------
/examples/monitor_system_available-interfaces.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Retrieve a list of all interfaces along with some meta information regarding their availability.
5 |
6 |
7 | Method
8 | https:///api/v2/monitor/system/available-interfaces
9 |
10 |
11 | CLI
12 |
13 | FG # sh sys int ?
14 | name Name.
15 | port1 static 0.0.0.0 0.0.0.0 192.168.0.1 255.255.255.0 up disable physical disable enable
16 | port2 static 0.0.0.0 0.0.0.0 1.1.1.1 255.255.255.0 up disable physical disable enable
17 | port3 static 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.0 up disable physical disable enable
18 | port4 static 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.0 up disable physical disable enable
19 | port5 static 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.0 up disable physical disable enable
20 | port6 static 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.0 up disable physical disable enable
21 | port7 static 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.0 up disable physical disable enable
22 | port8 static 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.0 up disable physical disable enable
23 | port9 static 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.0 up disable physical disable enable
24 | port10 static 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.0 up disable physical disable enable
25 | ssl.root static 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.0 up disable tunnel disable enable
26 |
27 |
28 | Response
29 | {
30 | "http_method": "GET",
31 | "results": [
32 | {
33 | "name": "any",
34 | "valid_in_policy": true,
35 | "icon": "fa-square-o"
36 | },
37 | {
38 | "name": "port1",
39 | "vdom": "root",
40 | "is_system_interface": true,
41 | "status": "up",
42 | "dhcp4_client_count": 0,
43 | "dhcp6_client_count": 0,
44 | "role": "undefined",
45 | "ipv4_addresses": [
46 | {
47 | "ip": "192.168.0.1",
48 | "netmask": "255.255.255.0",
49 | "cidr_netmask": 24
50 | }
51 | ],
52 | "mac_address": "00:50:56:01:68:fc",
53 | "link": "up",
54 | "duplex": "full",
55 | "speed": 1000,
56 | "supports_device_id": true,
57 | "valid_in_policy": true,
58 | "supports_fortitelemetry": true,
59 | "is_used": false,
60 | "is_physical": true,
61 | "media": "rj45",
62 | "managed_devices": [],
63 | "is_ipsecable": true,
64 | "is_routable": true,
65 | "tagging": [],
66 | "type": "physical",
67 | "icon": "ftnt-interface-rj45-up"
68 | },
69 | {
70 | "name": "port2",
71 | "vdom": "root",
72 | "is_system_interface": true,
73 | "status": "up",
74 | "dhcp4_client_count": 0,
75 | "dhcp6_client_count": 0,
76 | "role": "undefined",
77 | "ipv4_addresses": [
78 | {
79 | "ip": "1.1.1.1",
80 | "netmask": "255.255.255.0",
81 | "cidr_netmask": 24
82 | }
83 | ],
84 | "mac_address": "00:50:56:01:68:fd",
85 | "link": "up",
86 | "duplex": "full",
87 | "speed": 1000,
88 | "supports_device_id": true,
89 | "valid_in_policy": true,
90 | "supports_fortitelemetry": true,
91 | "is_used": false,
92 | "is_physical": true,
93 | "media": "rj45",
94 | "managed_devices": [],
95 | "is_ipsecable": true,
96 | "is_routable": true,
97 | "tagging": [],
98 | "type": "physical",
99 | "icon": "ftnt-interface-rj45-up"
100 | },
101 | {
102 | "name": "ssl.root",
103 | "vdom": "root",
104 | "is_system_interface": true,
105 | "status": "up",
106 | "alias": "SSL VPN interface",
107 | "role": "undefined",
108 | "mac_address": "00:00:00:00:00:00",
109 | "supports_fortitelemetry": true,
110 | "is_used": false,
111 | "is_sslvpn": true,
112 | "managed_devices": [],
113 | "tagging": [],
114 | "type": "tunnel",
115 | "icon": "ftnt-vpn-tunnel-up"
116 | },
117 | {
118 | "name": "virtual-wan-link",
119 | "is_virtual_wan_link": true,
120 | "status": "down",
121 | "role": "wan",
122 | "type": "virtual-wan",
123 | "load_balance_mode": "source-ip-based",
124 | "members": [],
125 | "icon": "ftnt-virtual-wan-link-down-disabled",
126 | "link": "down"
127 | }
128 | ],
129 | "vdom": "root",
130 | "path": "system",
131 | "name": "available-interfaces",
132 | "status": "success",
133 | "serial": "FGVM020000000000",
134 | "version": "v6.0.1",
135 | "build": 131
136 | }
137 | '''
138 |
139 | import os
140 | from pprint import pprint
141 | from fortiosapi import FortiOSAPI
142 |
143 | FG = FortiOSAPI()
144 |
145 | # Source _host
146 | FG_HOST = os.environ['FG_HOST']
147 | FG_USER = os.environ['FG_USER']
148 | FG_PASS = os.environ['FG_PASS']
149 |
150 | DEVICE = {
151 | 'host': FG_HOST,
152 | 'username': FG_USER,
153 | 'password': FG_PASS,
154 | }
155 |
156 | FG.login(**DEVICE)
157 |
158 | out = FG.monitor('system', 'available-interfaces')
159 |
160 | pprint(out)
161 |
162 | FG.logout()
163 |
--------------------------------------------------------------------------------
/examples/monitor_system_config-revision.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Returns a list of system configuration revisions.
5 |
6 |
7 | Method
8 | https:///api/v2/monitor/system/config-revision
9 |
10 |
11 | CLI
12 | FG # exec revision list config
13 | Last Firmware Version: V0.0.0-build000-REL0
14 |
15 | ID TIME ADMIN FIRMWARE VERSION COMMENT
16 | 1 2018-08-30 06:28:35 daemon_admin V6.0.0-build131-REL0 Automatic backup (upgrade)
17 | 2 2018-08-30 06:45:52 daemon_admin V6.0.0-build076-REL0 Automatic backup (upgrade)
18 |
19 |
20 | Response
21 | {
22 | "http_method": "GET",
23 | "results": {
24 | "revisions": [
25 | {
26 | "id": 1,
27 | "time": 1535635715,
28 | "version_id": "1",
29 | "admin": "daemon_admin",
30 | "comment": "Automatic backup (upgrade)"
31 | },
32 | {
33 | "id": 2,
34 | "time": 1535636752,
35 | "version_id": "2",
36 | "admin": "daemon_admin",
37 | "comment": "Automatic backup (upgrade)"
38 | }
39 | ],
40 | "categories": {
41 | "1": {
42 | "major_version": 6,
43 | "minor_version": 0,
44 | "patch_number": 0,
45 | "build_number": 131,
46 | "release_number": 0
47 | },
48 | "2": {
49 | "major_version": 6,
50 | "minor_version": 0,
51 | "patch_number": 0,
52 | "build_number": 76,
53 | "release_number": 0
54 | }
55 | },
56 | "current_config_unsaved": true
57 | },
58 | "vdom": "root",
59 | "path": "system",
60 | "name": "config-revision",
61 | "status": "success",
62 | "serial": "FGVM020000000000",
63 | "version": "v6.0.1",
64 | "build": 131
65 | }
66 | '''
67 |
68 | import os
69 | from pprint import pprint
70 | from fortiosapi import FortiOSAPI
71 |
72 | FG = FortiOSAPI()
73 |
74 | # Source _host
75 | FG_HOST = os.environ['FG_HOST']
76 | FG_USER = os.environ['FG_USER']
77 | FG_PASS = os.environ['FG_PASS']
78 |
79 | DEVICE = {
80 | 'host': FG_HOST,
81 | 'username': FG_USER,
82 | 'password': FG_PASS,
83 | }
84 |
85 | FG.login(**DEVICE)
86 |
87 | out = FG.monitor('system', 'config-revision')
88 |
89 | pprint(out)
90 |
91 | FG.logout()
92 |
--------------------------------------------------------------------------------
/examples/monitor_system_config-revision_file.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Download a specific configuration revision.
5 |
6 |
7 | Method
8 | https:///api/v2/monitor/system/config-revision/file?config_id=1
9 |
10 |
11 | CLI
12 | NA
13 |
14 |
15 | Response
16 | Object
17 | '''
18 |
19 | import os
20 | from pprint import pprint
21 | from fortiosapi import FortiOSAPI
22 |
23 | FG = FortiOSAPI()
24 |
25 | # Source _host
26 | FG_HOST = os.environ['FG_HOST']
27 | FG_USER = os.environ['FG_USER']
28 | FG_PASS = os.environ['FG_PASS']
29 |
30 | DEVICE = {
31 | 'host': FG_HOST,
32 | 'username': FG_USER,
33 | 'password': FG_PASS,
34 | }
35 |
36 | FG.login(**DEVICE)
37 |
38 | param = {
39 | 'config_id': 1,
40 | }
41 |
42 | out = FG.download('system', 'config-revision/file', parameters=param)
43 |
44 | with open("fg_revision.txt", "w") as f:
45 | f.write(out.text)
46 |
47 | pprint(out)
48 |
49 | FG.logout()
50 |
--------------------------------------------------------------------------------
/examples/monitor_system_config-revision_save.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Create a new config revision checkpoint.
5 |
6 |
7 | Method
8 | https:///api/v2/monitor/system/config-revision/save
9 |
10 |
11 | CLI
12 | NA
13 |
14 |
15 | Response
16 | NA
17 | '''
18 |
19 | import os
20 | import json
21 | from pprint import pprint
22 | from fortiosapi import FortiOSAPI
23 |
24 | FG = FortiOSAPI()
25 |
26 | # Source _host
27 | FG_HOST = os.environ['FG_HOST']
28 | FG_USER = os.environ['FG_USER']
29 | FG_PASS = os.environ['FG_PASS']
30 |
31 | DEVICE = {
32 | 'host': FG_HOST,
33 | 'username': FG_USER,
34 | 'password': FG_PASS,
35 | }
36 |
37 | FG.login(**DEVICE)
38 |
39 | # out = FG.monitor('system', 'config-revision/save')
40 |
41 | COMMENTS = {
42 | 'comments': 'new config revision',
43 | }
44 |
45 | COMMENTS = json.dumps(COMMENTS)
46 |
47 | # Using upload method because it's the easiest way to POST to
48 | # /monitor using fortiosapi at the moment
49 | FG.upload('system', 'config-revision/save', data=COMMENTS)
50 |
51 |
52 | # Check
53 | out = FG.monitor('system', 'config-revision')
54 |
55 | pprint(out)
56 |
57 | FG.logout()
58 |
--------------------------------------------------------------------------------
/examples/monitor_system_config_backup-vdom.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Backup system config for a specific VDOM
5 |
6 | Method
7 | https:///api/v2/monitor/system/config/backup?scope=vdom&vdom=vd01
8 |
9 |
10 | CLI
11 | FG # conf vd
12 | FG (vdom) # ed vd01
13 | current vf=vd01:3
14 |
15 | FG (vd01) # sh full-configuration
16 | config wireless-controller hotspot20 anqp-venue-name
17 | end
18 | ...
19 |
20 | Response
21 | Object
22 | '''
23 |
24 | import os
25 | from pprint import pprint
26 | from fortiosapi import FortiOSAPI
27 |
28 | FG = FortiOSAPI()
29 |
30 | # Source _host
31 | FG_HOST = os.environ['FG_HOST']
32 | FG_USER = os.environ['FG_USER']
33 | FG_PASS = os.environ['FG_PASS']
34 |
35 | DEVICE = {
36 | 'host': FG_HOST,
37 | 'username': FG_USER,
38 | 'password': FG_PASS,
39 | }
40 |
41 | FG.login(**DEVICE)
42 |
43 | param = {
44 | 'scope': 'vdom',
45 | 'vdom': 'vd01',
46 | }
47 |
48 | out = FG.download('system', 'config/backup', parameters=param)
49 |
50 | with open("fg_backup_vdom.txt", "w") as f:
51 | f.write(out.text)
52 |
53 | FG.logout()
54 |
--------------------------------------------------------------------------------
/examples/monitor_system_config_backup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Backup system config
5 |
6 | Method
7 | https:///api/v2/monitor/system/config/backup?scope=global
8 |
9 |
10 | CLI
11 | FG # show full-configuration
12 | #config-version=FG81EP-6.0.2-FW-build0163-180725:opmode=1:vdom=0:user=admin
13 | #conf_file_ver=380263519573911
14 | #buildno=0163
15 | #global_vdom=1
16 | config system global
17 | set admin-concurrent enable
18 | set admin-console-timeout 0
19 | set admin-https-pki-required disable
20 | set admin-https-redirect enable
21 | set admin-https-ssl-versions tlsv1-1 tlsv1-2
22 | set admin-lockout-duration 60
23 | ....
24 |
25 |
26 | Response
27 | Object
28 | '''
29 |
30 | import os
31 | from pprint import pprint
32 | from fortiosapi import FortiOSAPI
33 |
34 | FG = FortiOSAPI()
35 |
36 | # Source _host
37 | FG_HOST = os.environ['FG_HOST']
38 | FG_USER = os.environ['FG_USER']
39 | FG_PASS = os.environ['FG_PASS']
40 |
41 | DEVICE = {
42 | 'host': FG_HOST,
43 | 'username': FG_USER,
44 | 'password': FG_PASS,
45 | }
46 |
47 | FG.login(**DEVICE)
48 |
49 | param = {
50 | 'scope': 'global',
51 | }
52 |
53 | out = FG.download('system', 'config/backup', parameters=param)
54 |
55 | with open("fg_backup.txt", "w") as f:
56 | f.write(out.text)
57 |
58 | FG.logout()
59 |
--------------------------------------------------------------------------------
/examples/monitor_system_config_restore.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Restore system configuration from uploaded file or from USB.
5 |
6 | Method
7 | https:///api/v2/monitor/system/config/restore
8 |
9 |
10 | CLI
11 | NA
12 |
13 |
14 | Response
15 | NA
16 | '''
17 |
18 | import os
19 | from pprint import pprint
20 | from fortiosapi import FortiOSAPI
21 |
22 | FG = FortiOSAPI()
23 |
24 | # Source _host
25 | FG_HOST = os.environ['FG_HOST']
26 | FG_USER = os.environ['FG_USER']
27 | FG_PASS = os.environ['FG_PASS']
28 |
29 | DEVICE = {
30 | 'host': FG_HOST,
31 | 'username': FG_USER,
32 | 'password': FG_PASS,
33 | }
34 |
35 | FG.login(**DEVICE)
36 |
37 |
38 | filename = 'fg_backup.txt'
39 | f = open(filename)
40 |
41 | data = {
42 | 'source': 'upload',
43 | 'scope': 'global',
44 | }
45 |
46 | backup_file = {'file': (filename, f, 'text/plain')}
47 |
48 | FG.upload('system', 'config/restore', data=data, files=backup_file)
49 |
50 | # Will reboot automatically after POST
--------------------------------------------------------------------------------
/examples/monitor_system_firmware.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Retrieve a list of firmware images available to use for upgrade on this device.
5 |
6 | Method
7 | https:///api/v2/monitor/system/firmware
8 |
9 |
10 | CLI
11 | FG # diag fdsm image-list
12 | Last update: 0 secs ago.
13 |
14 | 06000000FIMG0012000002 v6.0 GA P2 b0163 (upgrade)
15 | 06000000FIMG0012000001 v6.0 GA P1 b0131 (upgrade)
16 | 05006000FIMG0012006005 v5.6 GA P5 b1600 (downgrade)
17 | 05006000FIMG0012006004 v5.6 GA P4 b1575 (downgrade)
18 | 05006000FIMG0012006003 v5.6 GA P3 b1547 (downgrade)
19 | 05006000FIMG0012006002 v5.6 GA P2 b1486 (downgrade)
20 |
21 |
22 | JSON
23 | {
24 | "http_method":"GET",
25 | "results":{
26 | "current":{
27 | "name":"FortiOS",
28 | "id":"current",
29 | "version":"v6.0.0",
30 | "major":6,
31 | "minor":0,
32 | "patch":0,
33 | "build":76,
34 | "branch-point":76,
35 | "release-type":"GA",
36 | "notes":"http:\/\/docs.fortinet.com\/d\/fortios-6.0.0-release-notes\/download",
37 | "source":"current",
38 | "platform-id":"FGVM64"
39 | },
40 | "available":[
41 | {
42 | "name":"FortiOS",
43 | "id":"06000000FIMG0012000002",
44 | "version":"v6.0.2",
45 | "major":6,
46 | "minor":0,
47 | "patch":2,
48 | "build":163,
49 | "branch-point":163,
50 | "release-type":"GA",
51 | "notes":"http:\/\/docs.fortinet.com\/d\/fortios-6.0.2-release-notes\/download",
52 | "source":"fortiguard"
53 | },
54 | ...,
55 | {
56 | "name":"FortiOS",
57 | "id":"05006000FIMG0012006002",
58 | "version":"v5.6.2",
59 | "major":5,
60 | "minor":6,
61 | "patch":2,
62 | "build":1486,
63 | "branch-point":1486,
64 | "release-type":"GA",
65 | "notes":"http:\/\/docs.fortinet.com\/d\/fortios-5.6.2-release-notes\/download",
66 | "source":"fortiguard"
67 | }
68 | ]
69 | },
70 | "vdom":"root",
71 | "path":"system",
72 | "name":"firmware",
73 | "status":"success",
74 | "serial":"FGVM020000000000",
75 | "version":"v6.0.0",
76 | "build":76
77 | }
78 |
79 | '''
80 |
81 | import os
82 | from pprint import pprint
83 | from fortiosapi import FortiOSAPI
84 |
85 |
86 | fgt = FortiOSAPI()
87 |
88 | # Source _host
89 | FG_HOST = os.environ['FG_HOST']
90 | FG_USER = os.environ['FG_USER']
91 | FG_PASS = os.environ['FG_PASS']
92 |
93 | DEVICE = {
94 | 'host': FG_HOST,
95 | 'username': FG_USER,
96 | 'password': FG_PASS,
97 | }
98 |
99 | fgt.login(**DEVICE)
100 |
101 | out = fgt.monitor('system', 'firmware')
102 |
103 | pprint(out)
104 |
105 | fgt.logout()
106 |
--------------------------------------------------------------------------------
/examples/monitor_system_firmware_upgrade-local_file.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Upgrade firmware image on this device using uploaded file.
5 |
6 | Method
7 | https:///api/v2/monitor/system/firmware/upgrade/
8 |
9 |
10 | CLI
11 | NA
12 |
13 |
14 | Debug
15 | FG # diag debug ena
16 | FG # d de app httpsd -1
17 |
18 | [httpsd 179 - 1536284801 info] ap_invoke_handler[593] -- new request (handler='api_monitor_v2-handler', uri='/api/v2/monitor/system/firmware/upgrade', method='POST')
19 | [httpsd 179 - 1536284801 info] ap_invoke_handler[597] -- User-Agent: python-requests/2.19.1
20 | [httpsd 179 - 1536284801 info] ap_invoke_handler[600] -- Source: 192.168.0.120:62279 Destination: 192.168.0.30:443
21 | [httpsd 179 - 1536284801 info] endpoint_handle_req[616] -- received api_monitor_v2_request from '192.168.0.120'
22 | [httpsd 179 - 1536284801 info] aps_init_process_vdom[1195] -- initialized process vdom to 'root' (cookie='(null)')
23 | [httpsd 179 - 1536284825 info] api_store_parameter[227] -- add API parameter 'source': '"upload"' (type=string)
24 | [httpsd 179 - 1536284825 info] api_store_parameter[227] -- add API parameter 'scope': '"global"' (type=string)
25 | [httpsd 179 - 1536284825 info] api_store_parameter[227] -- add API parameter 'file': '"FGT_VM64-v6-build0163-FORTINET.out"' (type=string)
26 | [httpsd 179 - 1536284825 info] api_store_parameter[227] -- add API parameter 'source': '"upload"' (type=string)
27 | [httpsd 179 - 1536284825 info] api_store_parameter[227] -- add API parameter 'scope': '"global"' (type=string)
28 | [httpsd 179 - 1536284825 info] api_store_parameter[227] -- add API parameter 'file': '"FGT_VM64-v6-build0163-FORTINET.out"' (type=string)
29 | [httpsd 179 - 1536284825 info] endpoint_process_req_vdom[457] -- new API request (action='upgrade',path='system',name='firmware',vdom='root',user='admin')
30 | [httpsd 179 - 1536284825 info] system_firmware_upgrade[1662] -- upgrade attempt for '/tmp/upfile'
31 | [httpsd 179 - 1536284825 error] system_firmware_upgrade[1666] -- upgrade initiated for '/tmp/upfile'
32 | [httpsd 179 - 1536284826 info] system_firmware_upgrade[1673] -- upgrade success for '/tmp/upfile'
33 | [httpsd 179 - 1536284826 info] ap_invoke_handler[616] -- request completed (handler='api_monitor_v2-handler' result==0)
34 | [httpsd 140 - 1536284829 error] log_error_core[439] -- [Fri Sep 7 01:47:09 2018] [notice] caught SIGTERM, shutting down
35 | '''
36 |
37 | import os
38 | import base64
39 | import json
40 | from fortiosapi import FortiOSAPI
41 |
42 |
43 | FG = FortiOSAPI()
44 |
45 | # Source _host
46 | FG_HOST = os.environ['FG_HOST']
47 | FG_USER = os.environ['FG_USER']
48 | FG_PASS = os.environ['FG_PASS']
49 |
50 | DEVICE = {
51 | 'host': FG_HOST,
52 | 'username': FG_USER,
53 | 'password': FG_PASS,
54 | }
55 |
56 | FG.login(**DEVICE)
57 |
58 | filename = 'FGT_VM64-v6-build0163-FORTINET.out'
59 | f = open(filename, 'rb')
60 | firmware_file = {'file': (filename, f, 'text/plain')}
61 |
62 | data = {
63 | 'source': 'upload',
64 | 'scope': 'global',
65 | }
66 |
67 | FG.upload('system', 'firmware/upgrade', data=data, files=firmware_file)
68 |
69 | # Will reboot automatically after POST
70 |
--------------------------------------------------------------------------------
/examples/monitor_system_firmware_upgrade-paths.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Retrieve a list of supported firmware upgrade paths.
5 |
6 | Method
7 | https:///api/v2/monitor/system/firmware/upgrade-paths/
8 |
9 |
10 | CLI
11 | NA
12 |
13 |
14 | Response
15 | {
16 | "http_method": "GET",
17 | "results": [
18 | {
19 | "from": {
20 | "major": 6,
21 | "minor": 0,
22 | "patch": 1,
23 | "build": 131
24 | },
25 | "to": {
26 | "major": 6,
27 | "minor": 0,
28 | "patch": 2,
29 | "build": 163
30 | }
31 | },
32 | ...
33 | {
34 | "from": {
35 | "major": 5,
36 | "minor": 2,
37 | "patch": 12,
38 | "build": 760
39 | },
40 | "to": {
41 | "major": 5,
42 | "minor": 4,
43 | "patch": 9,
44 | "build": 1202
45 | }
46 | }
47 | ],
48 | "vdom": "root",
49 | "path": "system",
50 | "name": "firmware",
51 | "action": "upgrade-paths",
52 | "status": "success",
53 | "serial": "FGVM020000000000",
54 | "version": "v6.0.0",
55 | "build": 76
56 | }
57 | '''
58 |
59 | import os
60 | from pprint import pprint
61 | from fortiosapi import FortiOSAPI
62 |
63 | FG = FortiOSAPI()
64 |
65 | # Source _host
66 | FG_HOST = os.environ['FG_HOST']
67 | FG_USER = os.environ['FG_USER']
68 | FG_PASS = os.environ['FG_PASS']
69 |
70 | DEVICE = {
71 | 'host': FG_HOST,
72 | 'username': FG_USER,
73 | 'password': FG_PASS,
74 | }
75 |
76 | FG.login(**DEVICE)
77 |
78 | out = FG.monitor('system', 'firmware/upgrade-paths')
79 |
80 | pprint(out)
81 |
82 | FG.logout()
83 |
--------------------------------------------------------------------------------
/examples/monitor_system_firmware_upgrade.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Upgrade firmware image on this device using uploaded file.
5 |
6 | Method
7 | https:///api/v2/monitor/system/firmware/upgrade/
8 |
9 |
10 | CLI
11 | NA
12 |
13 |
14 | Debug
15 |
16 | FG # diag debug ena
17 | FG # d de app httpsd -1
18 |
19 | [httpsd 181 - 1535636630 info] ap_invoke_handler[593] -- new request (handler='api_monitor_v2-handler', uri='/api/v2/monitor/system/firmware/upgrade', method='POST')
20 | [httpsd 181 - 1535636630 info] ap_invoke_handler[597] -- User-Agent: python-requests/2.19.1
21 | [httpsd 181 - 1535636630 info] ap_invoke_handler[600] -- Source: 172.30.248.57:53110 Destination: 192.168.0.1:443
22 | [httpsd 181 - 1535636630 info] endpoint_handle_req[594] -- received api_monitor_v2_request from '172.30.248.57'
23 | [httpsd 181 - 1535636630 info] aps_init_process_vdom[1163] -- initialized process vdom to 'root' (cookie='(null)')
24 | [httpsd 181 - 1535636630 info] api_store_parameter[227] -- add API parameter 'source': '"fortiguard"' (type=string)
25 | [httpsd 181 - 1535636630 info] api_store_parameter[227] -- add API parameter 'filename': '"06000000FIMG0012000000"' (type=string)
26 | [httpsd 181 - 1535636630 info] endpoint_process_req_vdom[444] -- new API request (action='upgrade',path='system',name='firmware',vdom='root',user='admin')
27 | [httpsd 181 - 1535636630 info] system_firmware_upgrade[1635] -- firmware upgrade attempt from management station for image '06000000FIMG0012000000'
28 | [httpsd 181 - 1535636643 info] _system_firmware_download_fds[1549] -- firmware download state: 0
29 | [httpsd 181 - 1535636643 info] system_firmware_upgrade[1648] -- upgrade attempt for '/tmp/fdsm.out'
30 | [httpsd 181 - 1535636643 error] system_firmware_upgrade[1652] -- upgrade initiated for '/tmp/fdsm.out'
31 | [httpsd 181 - 1535636643 info] system_firmware_upgrade[1659] -- upgrade success for '/tmp/fdsm.out'
32 | [httpsd 181 - 1535636643 info] ap_invoke_handler[616] -- request completed (handler='api_monitor_v2-handler' result==0)
33 | '''
34 |
35 | import os
36 | import json
37 | from fortiosapi import FortiOSAPI
38 |
39 |
40 | FG = FortiOSAPI()
41 |
42 | # Source _host
43 | FG_HOST = os.environ['FG_HOST']
44 | FG_USER = os.environ['FG_USER']
45 | FG_PASS = os.environ['FG_PASS']
46 |
47 | DEVICE = {
48 | 'host': FG_HOST,
49 | 'username': FG_USER,
50 | 'password': FG_PASS,
51 | }
52 |
53 | FG.login(**DEVICE)
54 |
55 | # Obtain FIRMWARE_ID with monitor_system_firmware
56 | FIRMWARE_ID = '06000000FIMG0012000000' # 6.0.0
57 | # FIRMWARE_ID = '06000000FIMG0012000001' # 6.0.1
58 |
59 | UPLOAD_DATA = {
60 | 'source': 'fortiguard',
61 | 'filename': FIRMWARE_ID,
62 | }
63 |
64 | UPLOAD_DATA = json.dumps(UPLOAD_DATA)
65 |
66 | FG.upload('system', 'firmware/upgrade', data=UPLOAD_DATA)
67 |
--------------------------------------------------------------------------------
/examples/monitor_system_interface.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Retrieve statistics for all system interfaces.
5 |
6 | # DEPRECATED - Use monitor/system/available-interfaces
7 |
8 | Method
9 | https:///api/v2/monitor/system/interface
10 |
11 |
12 | CLI
13 | NA
14 |
15 |
16 | Response
17 | {
18 | "http_method": "GET",
19 | "revision": "1535638688.393018",
20 | "results": {
21 | "wan1": {
22 | "id": "wan1",
23 | "name": "wan1",
24 | "alias": "",
25 | "mac": "00:00:00:00:00:00",
26 | "ip": "189.120.3.56",
27 | "mask": 22,
28 | "link": true,
29 | "speed": 1000,
30 | "duplex": 1,
31 | "tx_packets": 26191632,
32 | "rx_packets": 39051742,
33 | "tx_bytes": 16913986143,
34 | "rx_bytes": 42061215535,
35 | "tx_errors": 0,
36 | "rx_errors": 0
37 | },
38 | ...
39 |
40 | "nyarlathotep": {
41 | "id": "nyarlathotep",
42 | "name": "nyarlathotep",
43 | "alias": "",
44 | "mac": "00:00:00:00:00:00",
45 | "ip": "192.168.10.1",
46 | "mask": 24,
47 | "link": true,
48 | "speed": 0,
49 | "duplex": 0,
50 | "tx_packets": 7326324,
51 | "rx_packets": 6027,
52 | "tx_bytes": 4140970457,
53 | "rx_bytes": 259836,
54 | "tx_errors": 0,
55 | "rx_errors": 0
56 | },
57 | "mesh": {
58 | "id": "mesh",
59 | "name": "mesh",
60 | "alias": "",
61 | "mac": "00:00:00:00:00:00",
62 | "ip": "0.0.0.0",
63 | "mask": 0,
64 | "link": true,
65 | "speed": 0,
66 | "duplex": 0,
67 | "tx_packets": 0,
68 | "rx_packets": 0,
69 | "tx_bytes": 0,
70 | "rx_bytes": 0,
71 | "tx_errors": 0,
72 | "rx_errors": 0
73 | }
74 | },
75 | "vdom": "root",
76 | "path": "system",
77 | "name": "interface",
78 | "status": "success",
79 | "serial": "FG81EP4Q17002868",
80 | "version": "v6.0.2",
81 | "build": 163
82 | }
83 | '''
84 |
85 | import os
86 | from pprint import pprint
87 | from fortiosapi import FortiOSAPI
88 |
89 | FG = FortiOSAPI()
90 |
91 | # Source _host
92 | FG_HOST = os.environ['FG_HOST']
93 | FG_USER = os.environ['FG_USER']
94 | FG_PASS = os.environ['FG_PASS']
95 |
96 | DEVICE = {
97 | 'host': FG_HOST,
98 | 'username': FG_USER,
99 | 'password': FG_PASS,
100 | }
101 |
102 | FG.login(**DEVICE)
103 |
104 | out = FG.monitor('system', 'interface')
105 |
106 | pprint(out)
107 |
108 | FG.logout()
109 |
--------------------------------------------------------------------------------
/examples/monitor_system_os_reboot.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Immediately reboot this device.
5 |
6 | Method
7 | https:///api/v2/monitor/system/firmware/upgrade/
8 |
9 |
10 | CLI
11 | NA
12 |
13 |
14 | Debug
15 | NA
16 | '''
17 |
18 | import os
19 | import json
20 | from fortiosapi import FortiOSAPI
21 |
22 |
23 | FG = FortiOSAPI()
24 |
25 | # Source _host
26 | FG_HOST = os.environ['FG_HOST']
27 | FG_USER = os.environ['FG_USER']
28 | FG_PASS = os.environ['FG_PASS']
29 |
30 | DEVICE = {
31 | 'host': FG_HOST,
32 | 'username': FG_USER,
33 | 'password': FG_PASS,
34 | }
35 |
36 | FG.login(**DEVICE)
37 |
38 | UPLOAD_DATA = {
39 | 'event_log_message': 'going down',
40 | }
41 |
42 | UPLOAD_DATA = json.dumps(UPLOAD_DATA)
43 |
44 | # Using upload method because it's the easiest way to POST to
45 | # /monitor using fortiosapi at the moment
46 | FG.upload('system', 'os/reboot', data=UPLOAD_DATA)
47 |
48 |
49 | '''
50 | Currently this code works but will hang at the end and will raise the following errors:
51 |
52 | Traceback (most recent call last):
53 | File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
54 | chunked=chunked)
55 | File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 384, in _make_request
56 | six.raise_from(e, None)
57 | File "", line 2, in raise_from
58 | File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 380, in _make_request
59 | httplib_response = conn.getresponse()
60 | File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse
61 | response.begin()
62 | File "/usr/lib/python3.5/http/client.py", line 297, in begin
63 | version, status, reason = self._read_status()
64 | File "/usr/lib/python3.5/http/client.py", line 266, in _read_status
65 | raise RemoteDisconnected("Remote end closed connection without"
66 | http.client.RemoteDisconnected: Remote end closed connection without response
67 |
68 | During handling of the above exception, another exception occurred:
69 |
70 | Traceback (most recent call last):
71 | File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 445, in send
72 | timeout=timeout
73 | File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
74 | _stacktrace=sys.exc_info()[2])
75 | File "/usr/local/lib/python3.5/dist-packages/urllib3/util/retry.py", line 367, in increment
76 | raise six.reraise(type(error), error, _stacktrace)
77 | File "/usr/local/lib/python3.5/dist-packages/urllib3/packages/six.py", line 685, in reraise
78 | raise value.with_traceback(tb)
79 | File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
80 | chunked=chunked)
81 | File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 384, in _make_request
82 | six.raise_from(e, None)
83 | File "", line 2, in raise_from
84 | File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 380, in _make_request
85 | httplib_response = conn.getresponse()
86 | File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse
87 | response.begin()
88 | File "/usr/lib/python3.5/http/client.py", line 297, in begin
89 | version, status, reason = self._read_status()
90 | File "/usr/lib/python3.5/http/client.py", line 266, in _read_status
91 | raise RemoteDisconnected("Remote end closed connection without"
92 | urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
93 |
94 | During handling of the above exception, another exception occurred:
95 |
96 | Traceback (most recent call last):
97 | File "./monitor_system_os_reboot.py", line 67, in
98 | FG.upload('system', 'os/reboot', data=UPLOAD_DATA)
99 | File "/usr/local/lib/python3.5/dist-packages/fortiosapi/fortiosapi.py", line 204, in upload
100 | data=data, files=files)
101 | File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 559, in post
102 | return self.request('POST', url, data=data, json=json, **kwargs)
103 | File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 512, in request
104 | resp = self.send(prep, **send_kwargs)
105 | File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 622, in send
106 | r = adapter.send(request, **kwargs)
107 | File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 495, in send
108 | raise ConnectionError(err, request=request)
109 | requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
110 | '''
111 |
--------------------------------------------------------------------------------
/examples/monitor_system_os_shutdown.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Immediately shutdown this device.
5 |
6 | Method
7 | https:///api/v2/monitor/system/os/shutdown
8 |
9 |
10 | CLI
11 | NA
12 |
13 |
14 | Debug
15 | NA
16 | '''
17 |
18 | import os
19 | import json
20 | from fortiosapi import FortiOSAPI
21 |
22 |
23 | FG = FortiOSAPI()
24 |
25 | # Source _host
26 | FG_HOST = os.environ['FG_HOST']
27 | FG_USER = os.environ['FG_USER']
28 | FG_PASS = os.environ['FG_PASS']
29 |
30 | DEVICE = {
31 | 'host': FG_HOST,
32 | 'username': FG_USER,
33 | 'password': FG_PASS,
34 | }
35 |
36 | FG.login(**DEVICE)
37 |
38 | UPLOAD_DATA = {
39 | 'event_log_message': 'going down',
40 | }
41 |
42 | UPLOAD_DATA = json.dumps(UPLOAD_DATA)
43 |
44 | # Using upload method because it's the easiest way to POST to
45 | # /monitor using fortiosapi at the moment
46 | FG.upload('system', 'os/shutdown', data=UPLOAD_DATA)
47 |
48 |
49 | '''
50 | Currently this code works but will hang at the end and will raise the following errors:
51 |
52 | Traceback (most recent call last):
53 | File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
54 | chunked=chunked)
55 | File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 384, in _make_request
56 | six.raise_from(e, None)
57 | File "", line 2, in raise_from
58 | File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 380, in _make_request
59 | httplib_response = conn.getresponse()
60 | File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse
61 | response.begin()
62 | File "/usr/lib/python3.5/http/client.py", line 297, in begin
63 | version, status, reason = self._read_status()
64 | File "/usr/lib/python3.5/http/client.py", line 266, in _read_status
65 | raise RemoteDisconnected("Remote end closed connection without"
66 | http.client.RemoteDisconnected: Remote end closed connection without response
67 |
68 | During handling of the above exception, another exception occurred:
69 |
70 | Traceback (most recent call last):
71 | File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 445, in send
72 | timeout=timeout
73 | File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
74 | _stacktrace=sys.exc_info()[2])
75 | File "/usr/local/lib/python3.5/dist-packages/urllib3/util/retry.py", line 367, in increment
76 | raise six.reraise(type(error), error, _stacktrace)
77 | File "/usr/local/lib/python3.5/dist-packages/urllib3/packages/six.py", line 685, in reraise
78 | raise value.with_traceback(tb)
79 | File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
80 | chunked=chunked)
81 | File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 384, in _make_request
82 | six.raise_from(e, None)
83 | File "", line 2, in raise_from
84 | File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 380, in _make_request
85 | httplib_response = conn.getresponse()
86 | File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse
87 | response.begin()
88 | File "/usr/lib/python3.5/http/client.py", line 297, in begin
89 | version, status, reason = self._read_status()
90 | File "/usr/lib/python3.5/http/client.py", line 266, in _read_status
91 | raise RemoteDisconnected("Remote end closed connection without"
92 | urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
93 |
94 | During handling of the above exception, another exception occurred:
95 |
96 | Traceback (most recent call last):
97 | File "./monitor_system_os_reboot.py", line 67, in
98 | FG.upload('system', 'os/reboot', data=UPLOAD_DATA)
99 | File "/usr/local/lib/python3.5/dist-packages/fortiosapi/fortiosapi.py", line 204, in upload
100 | data=data, files=files)
101 | File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 559, in post
102 | return self.request('POST', url, data=data, json=json, **kwargs)
103 | File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 512, in request
104 | resp = self.send(prep, **send_kwargs)
105 | File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 622, in send
106 | r = adapter.send(request, **kwargs)
107 | File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 495, in send
108 | raise ConnectionError(err, request=request)
109 | requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
110 | '''
111 |
--------------------------------------------------------------------------------
/examples/monitor_system_status.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Retrieve basic system status.
5 |
6 | Method
7 | https:///api/v2/monitor/system/status
8 |
9 | CLI
10 | NA
11 |
12 | JSON
13 | {
14 | "http_method":"GET",
15 | "results":{
16 | },
17 | "vdom":"root",
18 | "path":"system",
19 | "name":"status",
20 | "status":"success",
21 | "serial":"FGVM020000000000",
22 | "version":"v6.0.0",
23 | "build":76
24 | }
25 | '''
26 |
27 | import os
28 | from pprint import pprint
29 | from fortiosapi import FortiOSAPI
30 |
31 |
32 | FG = FortiOSAPI()
33 |
34 | # Source _host
35 | FG_HOST = os.environ['FG_HOST']
36 | FG_USER = os.environ['FG_USER']
37 | FG_PASS = os.environ['FG_PASS']
38 |
39 | DEVICE = {
40 | 'host': FG_HOST,
41 | 'username': FG_USER,
42 | 'password': FG_PASS,
43 | }
44 |
45 | FG.login(**DEVICE)
46 |
47 | out = FG.monitor('system', 'status')
48 |
49 | pprint(out)
50 |
51 | FG.logout()
52 |
--------------------------------------------------------------------------------
/examples/monitor_system_vmlicense_upload.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | Update VM license using uploaded file. Reboots immediately if successful.
5 |
6 | Method
7 | https:///api/v2/monitor/system/vmlicense/upload/
8 |
9 |
10 | CLI
11 | NA
12 |
13 |
14 | Response
15 | NA
16 | '''
17 |
18 | import os
19 | from pprint import pprint
20 | from fortiosapi import FortiOSAPI
21 |
22 | FG = FortiOSAPI()
23 |
24 | # Source _host
25 | FG_HOST = os.environ['FG_HOST']
26 | FG_USER = os.environ['FG_USER']
27 | FG_PASS = os.environ['FG_PASS']
28 |
29 | DEVICE = {
30 | 'host': FG_HOST,
31 | 'username': FG_USER,
32 | 'password': FG_PASS,
33 | }
34 |
35 | FG._https = False # Connect using http before license is applied
36 | FG.login(**DEVICE)
37 |
38 |
39 | filename = 'license.lic'
40 | f = open(filename)
41 |
42 | data = {
43 | 'source': 'upload',
44 | 'scope': 'global',
45 | }
46 |
47 | license_file = {'file': (filename, f, 'text/plain')}
48 |
49 | FG.upload('system', 'vmlicense/upload', data=data, files=license_file)
50 |
51 | # Will reboot automatically after POST
--------------------------------------------------------------------------------
/gatepy/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mbdraks/gatepy/81a573a405b8b36d8a5a12b26c61b7b961e7075e/gatepy/__init__.py
--------------------------------------------------------------------------------
/gatepy/cmdb.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 |
5 | Module for Fortinet FortiOS CMDB API
6 |
7 | '''
8 |
9 | import os
10 | import requests
11 | from fortiosapi import FortiOSAPI
12 |
13 | class FortinetFortiGateCMDB(FortiOSAPI):
14 | """FortinetFortiGate Class
15 |
16 | This class will be used to extend the functions of the original
17 | FortiOSAPI class
18 |
19 | """
20 | def __init__(self):
21 | self._https = True
22 | self._fortiversion = "Version is set when logged"
23 | self._session = requests.session()
24 | self._session.verify = False
25 |
26 | def get_cmdb_system_interfaces(self, interface_name=None):
27 | """Get configured interfaces.
28 |
29 | Args:
30 | interface_name (str, optional): Filter results by interface name
31 |
32 | Returns:
33 | Configured interfaces as a list
34 |
35 | """
36 | if interface_name:
37 | filter = 'filter=name==' + interface_name
38 | else:
39 | filter = ''
40 | resp = self.get('system', 'interface', parameters=filter)
41 | if resp['status'] == 'success':
42 | if len(resp['results']) == 1: # if filtered resp will have only one interface config
43 | return resp['results'][0] # return a dict instead of a list to make interface details easier to access
44 | return resp['results']
45 | else:
46 | return 'nok'
47 |
--------------------------------------------------------------------------------
/gatepy/gatepy.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''gatepy module
4 |
5 | FortinetFortiGate class will be used to extend the functions of the original
6 | FortiOSAPI class
7 | '''
8 |
9 | import os
10 | import requests
11 | from cmdb import FortinetFortiGateCMDB
12 | from monitor import FortinetFortiGateMonitor
13 |
14 | class FortinetFortiGate(FortinetFortiGateCMDB, FortinetFortiGateMonitor):
15 |
16 | def __init__(self):
17 | self._https = True
18 | self._fortiversion = "Version is set when logged"
19 | self._session = requests.session()
20 | self._session.verify = False
21 |
--------------------------------------------------------------------------------
/gatepy/monitor.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 |
5 | Module for Fortinet FortiOS Monitor API
6 |
7 | '''
8 |
9 | import os
10 | import requests
11 | from fortiosapi import FortiOSAPI
12 |
13 | class FortinetFortiGateMonitor(FortiOSAPI):
14 | """
15 | This class will be used to provide easy access to monitor endpoints
16 | of FortiOS API.
17 | """
18 | def __init__(self):
19 | self._https = True
20 | self._fortiversion = "Version is set when logged"
21 | self._session = requests.session()
22 | self._session.verify = False
23 |
24 | def get_monitor_firewall_policy_lookup( self,
25 | srcintf=None,
26 | sourceip=None,
27 | protocol=None,
28 | dest=None,
29 | destport=None,
30 | ):
31 | """Performs a policy lookup by creating a dummy packet and asking the kernel which policy would be hit.
32 |
33 | Args:
34 | ipv6 (bool, optional): Perform an IPv6 lookup
35 | srcintf (str): Source Interface
36 | sourceport (int, optional): Source Port
37 | sourceip (str): Source IP
38 | protocol (str): Protocol
39 | dest (str): Destination IP/FQDN
40 | destport (int): Destination Port
41 | icmptype (int, optional): ICMP Type
42 | icmpcode (int, optional): ICMP Code
43 |
44 |
45 | Returns:
46 | Policy ID of matched policy lookup
47 | """
48 |
49 | param = {
50 | 'srcintf': srcintf,
51 | 'sourceip': sourceip,
52 | 'protocol': protocol,
53 | 'dest': dest,
54 | 'destport': destport,
55 | }
56 |
57 | resp = self.monitor('firewall', 'policy-lookup', parameters=param)
58 |
59 | if resp['status'] == 'success':
60 | return resp['results']
61 | else:
62 | return 'nok'
63 |
64 | def get_monitor_firewall_policy(self, policyid=None):
65 | """List traffic statistics for IPv4 policies.
66 |
67 | Args:
68 | policyid (int, optional): Filter by Policy ID
69 |
70 | Returns:
71 | Traffic statistics for IPv4 policies.
72 | """
73 |
74 | if policyid:
75 | filter = 'policyid=' + str(policyid)
76 | else:
77 | filter = ''
78 |
79 | resp = self.monitor('firewall', 'policy', parameters=filter)
80 |
81 | if resp['status'] == 'success':
82 | return resp['results']
83 | else:
84 | return 'nok'
85 |
86 |
87 | def get_monitor_log_device_state(self):
88 | """Retrieve information on state of log devices.
89 |
90 | Returns:
91 | Retrieve information on state of log devices.
92 | """
93 |
94 | resp = self.monitor('log', 'device/state')
95 |
96 | if resp['status'] == 'success':
97 | return resp['results']
98 | else:
99 | return 'nok'
100 |
101 |
102 | def get_monitor_router_ipv4(self):
103 | """List all active IPv4 routing table entries
104 |
105 | Returns:
106 | NA
107 | """
108 |
109 | resp = self.monitor('router', 'ipv4')
110 |
111 | if resp['status'] == 'success':
112 | return resp['results']
113 | else:
114 | return 'nok'
115 |
116 |
117 | def get_monitor_system_available_interfaces(self, view_type=None):
118 | """Retrieve a list of all interfaces along with some meta information regarding their availability.
119 |
120 | Args:
121 | view_type (str, optional): Include additional information for interfaces, valid options are:
122 |
123 | * 'poe': Includes PoE information for supported ports.
124 | * 'ha': Includes extra meta information useful when dealing with interfaces related to HA configuration. Interfaces that are used by an HA cluster as management interfaces are also included in this view.
125 | * 'zone': Includes extra meta information for determining zone membership eligibility.
126 | * 'vwp': Includes extra meta information for determining virtual wire pair eligibility.
127 |
128 | Returns:
129 | Retrieve a list of all interfaces along with some meta information regarding their availability.
130 | """
131 |
132 | if view_type:
133 | filter = 'view_type=' + view_type
134 | else:
135 | filter = ''
136 |
137 | resp = self.monitor('system', 'available-interfaces', parameters=filter)
138 |
139 | if resp['status'] == 'success':
140 | return resp['results']
141 | else:
142 | return 'nok'
143 |
144 |
145 | def get_monitor_system_config_backup(self, scope='global', vdom=None):
146 | """List all active IPv4 routing table entries
147 |
148 | Args:
149 | scope (str): global or vdom
150 | vdom (str, optional): vdom name
151 |
152 | Returns:
153 | None
154 | """
155 |
156 | param = {
157 | 'scope': scope,
158 | }
159 |
160 | resp = self.download('system', 'config/backup', parameters=param)
161 |
162 | with open("fg_backup.txt", "w") as f:
163 | f.write(resp.text)
164 |
165 | if resp:
166 | return None
167 | else:
168 | return 'nok'
169 |
170 |
171 |
--------------------------------------------------------------------------------
/gatepy/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup, find_packages
2 |
3 | setup(
4 | name='gatepy',
5 | version='1.2.0',
6 | description='FortiGate Automation using REST API',
7 | classifiers=[
8 | 'Development Status :: 3 - Alpha',
9 | 'Intended Audience :: Developers',
10 | 'Programming Language :: Python :: 3',
11 | 'Programming Language :: Python :: 3.4',
12 | 'Programming Language :: Python :: 3.5',
13 | 'Programming Language :: Python :: 3.6',
14 | ],
15 | keywords='fortinet fortigate fortios',
16 | packages=find_packages(exclude=['contrib', 'docs', 'tests']),
17 | )
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | asn1crypto>=0.24.0
2 | bcrypt>=3.1.4
3 | certifi>=2018.8.24
4 | cffi>=1.11.5
5 | chardet>=3.0.4
6 | cryptography>=2.3.1
7 | fortiosapi>=0.9.91
8 | idna>=2.7
9 | paramiko>=2.4.1
10 | pyasn1>=0.4.4
11 | pycparser>=2.18
12 | PyNaCl>=1.2.1
13 | requests>=2.19.1
14 | six>=1.11.0
15 | urllib3>=1.23
16 |
--------------------------------------------------------------------------------
/samples/README.md:
--------------------------------------------------------------------------------
1 | # Examples
2 |
3 | This folder will contain example scripts to FortiOS API using the gatepy module, for examples using only fortiosapi check the 'examples' folder.
--------------------------------------------------------------------------------
/samples/cmdb_system_interface.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | ''' Obtain all configured info from interface port1'''
4 |
5 | import os
6 | from pprint import pprint
7 | import gatepy
8 |
9 | FG_HOST = os.environ['FG_HOST']
10 | FG_USER = os.environ['FG_USER']
11 | FG_PASS = os.environ['FG_PASS']
12 |
13 | DEVICE = {
14 | 'host': FG_HOST,
15 | 'username': FG_USER,
16 | 'password': FG_PASS,
17 | }
18 |
19 |
20 | def main():
21 | device = gatepy.FortinetFortiGate()
22 | device.login(**DEVICE)
23 | out = device.get_cmdb_system_interfaces('port1')
24 | pprint(out)
25 |
26 |
27 | if __name__ == '__main__':
28 | main()
29 |
--------------------------------------------------------------------------------
/samples/monitor_firewall_policy_lookup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''Performs a policy lookup'''
4 |
5 | import os
6 | from pprint import pprint
7 | import gatepy
8 |
9 | FG_HOST = os.environ['FG_HOST']
10 | FG_USER = os.environ['FG_USER']
11 | FG_PASS = os.environ['FG_PASS']
12 |
13 | DEVICE = {
14 | 'host': FG_HOST,
15 | 'username': FG_USER,
16 | 'password': FG_PASS,
17 | }
18 |
19 | lookup_parameters = {
20 | 'srcintf': 'port2',
21 | 'sourceip': '1.1.1.1',
22 | 'protocol': '6',
23 | 'dest': '10.0.0.10',
24 | 'destport': 80,
25 | }
26 |
27 | def main():
28 | device = gatepy.FortinetFortiGate()
29 | device.login(**DEVICE)
30 | out = device.get_monitor_firewall_policy_lookup(**lookup_parameters)
31 | device.logout()
32 | pprint(out)
33 |
34 |
35 | if __name__ == '__main__':
36 | main()
37 |
--------------------------------------------------------------------------------
/samples/monitor_license_status.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''Get license status'''
4 |
5 | import os
6 | from pprint import pprint
7 | import gatepy
8 |
9 | FG_HOST = os.environ['FG_HOST']
10 | FG_USER = os.environ['FG_USER']
11 | FG_PASS = os.environ['FG_PASS']
12 |
13 | DEVICE = {
14 | 'host': FG_HOST,
15 | 'username': FG_USER,
16 | 'password': FG_PASS,
17 | }
18 |
19 |
20 | def main():
21 | device = gatepy.FortinetFortiGate()
22 | device.login(**DEVICE)
23 | out = device.get_monitor_license_status()
24 | device.logout()
25 | pprint(out)
26 |
27 |
28 | if __name__ == '__main__':
29 | main()
30 |
--------------------------------------------------------------------------------
/samples/monitor_system_available-interfaces.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''Retrieve a list of all interfaces along with some meta info'''
4 |
5 | import os
6 | from pprint import pprint
7 | import gatepy
8 |
9 | FG_HOST = os.environ['FG_HOST']
10 | FG_USER = os.environ['FG_USER']
11 | FG_PASS = os.environ['FG_PASS']
12 |
13 | DEVICE = {
14 | 'host': FG_HOST,
15 | 'username': FG_USER,
16 | 'password': FG_PASS,
17 | }
18 |
19 |
20 | def main():
21 | device = gatepy.FortinetFortiGate()
22 | device.login(**DEVICE)
23 | out = device.get_monitor_system_available_interfaces()
24 | pprint(out)
25 |
26 |
27 | if __name__ == '__main__':
28 | main()
29 |
--------------------------------------------------------------------------------