Skip to content

Commit f92920c

Browse files
authored
Merge pull request #2679 from hmpf/modernize-scripts
Modernize scripts in bin/
2 parents 3c4f8bd + 300d891 commit f92920c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+221
-123
lines changed

.github/workflows/build-and-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- name: "Install test runner dependencies"
5050
run: |
5151
set -xe
52-
python -m pip install --upgrade 'pip==23.1.0' setuptools wheel 'tox<4' tox-gh-actions coverage virtualenv snmpsim 'pyasn1<0.5.0'
52+
python3 -m pip install --upgrade 'pip==23.1.0' setuptools wheel 'tox<4' tox-gh-actions coverage virtualenv snmpsim 'pyasn1<0.5.0'
5353
sudo apt-get install -y nbtscan
5454
5555
# virtualenv seems to currently be embedding a broken version of
@@ -80,7 +80,7 @@ jobs:
8080
export DISPLAY=:99
8181
ulimit -c unlimited
8282
sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t
83-
python -m tox
83+
python3 -m tox
8484
8585
- name: Upload Selenium driver logs (${{ matrix.python-version }})
8686
if: always()

NOTES.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,38 @@ please go to https://github.com/uninett/nav/milestones .
1111
NAV 5.9
1212
=======
1313

14+
Changed names of NAV command line programs
15+
------------------------------------------
16+
NAV has switched to a more canonical way of installing Python command line
17+
scripts, or "binaries". This means that all NAV command line programs that
18+
previously ended with a ``.py`` extension now have been stripped of that
19+
extension. Any custom cron jobs or scripts you have that may reference these
20+
NAV commands must be updated in order to continue working.
21+
22+
It also means that you need to make sure your :file:`daemons.yml` configuration
23+
file is up-to-date after an upgrade, as well as the NAV cronjob snippets in the
24+
:file:`cron.d/` configuration directory.
25+
26+
These commands are affected and no longer have a ``.py`` extension:
27+
28+
* ``alertengine``
29+
* ``autoenable``
30+
* ``collect_active_ip``
31+
* ``emailreports``
32+
* ``logengine``
33+
* ``macwatch``
34+
* ``mailin``
35+
* ``maintengine``
36+
* ``netbiostracker``
37+
* ``pping``
38+
* ``radiusparser``
39+
* ``servicemon``
40+
* ``smsd``
41+
* ``snmptrapd``
42+
* ``sortedstats_cacher``
43+
* ``start_arnold``
44+
* ``t1000``
45+
1446
Web security
1547
------------
1648

doc/hacking/hacking.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ A rough guide to the source tree:
113113
================================= =================================================================
114114
Directory Description
115115
================================= =================================================================
116-
:file:`bin/` NAV 'binaries'; executable scripts and programs.
117116
:file:`contrib/` User contributed NAV tools. NAV doesn't depend on these, and any
118117
maintenance of them is left up to the original developers. We do
119118
not offer support for these tools.

doc/reference/arnold.rst

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ several views available. They are as follows:
5454
In addition you have two actions you can use - *Search* and *Manual detention*.
5555

5656
- **Search** lets you search for detentions given some search parameters.
57-
- **Manual detention** lets you manually detain a port given an IP- or
57+
- **Manual detention** lets you manually detain a port given an IP- or
5858
MAC-address.
5959

6060
Predefined detentions
6161
---------------------
62-
The only way to use a predefined detention is by using the ``start_arnold.py``
62+
The only way to use a predefined detention is by using the ``start_arnold``
6363
shell script. After creating a predefined detention you usually want to create a
6464
cron-job for running the script with some input parameters. See section about
65-
`start_arnold.py`_.
65+
`start_arnold`_.
6666

6767

6868
Using the scripts
@@ -71,48 +71,48 @@ Using the scripts
7171
Arnold consists of three scripts, which all are located in the ``nav/bin``
7272
directory.
7373

74-
- **autoenable.py** enables ports based on the autoenable variable available for
74+
- **autoenable** enables ports based on the autoenable variable available for
7575
both manual and predefined detentions.
76-
- **start_arnold.py** is used in combination with predefined detentions to
76+
- **start_arnold** is used in combination with predefined detentions to
7777
invoke a series of detentions.
78-
- **t1000.py** verifies that the MAC-addresses that should be offline are not
78+
- **t1000** verifies that the MAC-addresses that should be offline are not
7979
active on other ports. If a detained MAC-address is online on another port, it
8080
will try to detain it there aswell.
8181

8282
More details about the different scripts can be seen below.
8383

84-
autoenable.py
85-
-------------
84+
autoenable
85+
----------
8686

87-
*autoenable.py* fetches all detained ports with an autoenable-value and enables
87+
*autoenable* fetches all detained ports with an autoenable-value and enables
8888
each of those detentions if the time is due. It can be run manually or as a
8989
periodic cron job.
9090

9191
The simplest way of running automatic enabling periodically is to create a file
92-
containing cron configuration that calls the *autoenable.py* program as often as
92+
containing cron configuration that calls the *autoenable* program as often as
9393
you would like::
9494

95-
0 * * * * some_prefix/nav/bin/autoenable.py # Run every hour on the hour
95+
0 * * * * some_prefix/nav/bin/autoenable # Run every hour on the hour
9696

9797
Save this snippet in a file called ``autoenable`` in NAV's ``etc/cron.d/``
9898
directory. That way, you can add it to the navcron user's crontab by calling
9999
``nav start autoenable``.
100100

101-
start_arnold.py
102-
---------------
101+
start_arnold
102+
------------
103103

104-
When a predefined detention is created you can use *start_arnold.py* to invoke a
104+
When a predefined detention is created you can use *start_arnold* to invoke a
105105
series of detentions based on the input to the script.
106106

107107
If the file or list of addresses exist locally then you can pipe it in using for
108108
instance ``cat``::
109-
110-
# cat scanresult.txt | nav/bin/start_arnold_py -i
109+
110+
# cat scanresult.txt | nav/bin/start_arnold -i
111111

112112
or you can do it from a remote server using ssh commands::
113113

114-
# cat scanresult.txt | ssh [email protected]:nav/bin/start_arnold_py -i
115-
114+
# cat scanresult.txt | ssh [email protected]:nav/bin/start_arnold -i
115+
116116
To avoid having to type passwords you want to create public keys, like described
117117
for instance `here <http://www.linuxproblem.org/art_9.html>`_.
118118

@@ -123,19 +123,19 @@ Each line in this file is assumed to consist of an IP- or MAC-address and
123123
optionally a comment (separated by a space). For each valid address a detention
124124
will be made. Lines starting with *#* will be skipped.
125125

126-
t1000.py
127-
--------
126+
t1000
127+
-----
128128

129-
This script needs to be set up to run in the same way as `autoenable.py`_.
129+
This script needs to be set up to run in the same way as `autoenable`_.
130130

131-
*t1000.py* fetches all detained ports and checks if the MAC-address which was
131+
*t1000* fetches all detained ports and checks if the MAC-address which was
132132
behind the detained port is active on another port. If it is, it enforces the
133133
detention on that port aswell. Depending on options given at detention-time it
134134
will either remove the detention on the old port or just leave it.
135135

136136
.. warning:: This does not detain the new port immediately after a detained
137137
computer has moved to it, because it takes some time before NAV discovers the
138-
new location of the MAC-address. This combined with the interval t1000.py
138+
new location of the MAC-address. This combined with the interval ``t1000``
139139
runs in could give the user quite some time with access before being detained
140140
again. This on-and-off behavior of internet access has been known to cause
141141
confusion and annoyance among the users - use this script knowing that.

doc/reference/mailin.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ connections from outside the server, or no messages will come through.
2424

2525
Pick an e-mail address on your NAV server to send 3rd party alerts to, for
2626
example `[email protected]`. Mail received at this address should be
27-
piped through the ``mailin.py`` program. This can usually be accomplished by
27+
piped through the ``mailin`` program. This can usually be accomplished by
2828
adding an e-mail alias to :file:`/etc/aliases`, like this::
2929

3030
cat >> /etc/aliases <<EOF
31-
mailin: "| /usr/local/nav/bin/mailin.py"
31+
mailin: "| /usr/local/nav/bin/mailin"
3232
EOF
3333
newaliases
3434

doc/reference/radius-install.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Copy the script to a location of your choice on the server where the
185185
that executes this script as often as you would like to make sure that the
186186
script is actually running. For example::
187187

188-
0 * * * * /path/to/radiusparser.py
188+
0 * * * * /path/to/radiusparser
189189

190190
This will run the script every hour, but if it detects that it is already
191191
running, it quits and leaves the running script alone.
@@ -210,14 +210,14 @@ accounting log table accumulating forever. To arrange for periodic
210210
deletion of old records, create a cron snippet in NAV's ``etc/cron.d/``
211211
directory called ``radiusclean`` and add the following lines to it::
212212

213-
50 5 * * 6 /path/to/navclean.py --radiusacct -E "3 months" -f
214-
45 5 * * 6 /path/to/navclean.py --radiuslog -E "1 month" -f
213+
50 5 * * 6 /path/to/navclean --radiusacct -E "3 months" -f
214+
45 5 * * 6 /path/to/navclean --radiuslog -E "1 month" -f
215215

216216
To insert the cron snippet into `navcron`'s crontab, run::
217217

218218
sudo nav start radiusclean
219219

220-
This will run the ``navclean.py`` program once a week, deleting all radius
220+
This will run the ``navclean`` program once a week, deleting all radius
221221
accounting entries older than three months and all radius error log entries
222222
older than one month. Feel free to change the intervals to something you
223223
think is suitable for your organization.

doc/reference/radius.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ Files
2121
doc/README.txt What you are probably reading right now :]
2222
doc/INSTALL.txt How to install the radius accounting subsystem
2323

24-
bin/navclean.py Modified version of navclean.py, that also handles
24+
bin/navclean Modified version of navclean.py, that also handles
2525
the radius accounting table. Should probably me made
2626
to also handle the log table, or dropped all together.
27-
bin/radiusparser.py radius.log parser that inserts data into the database.
27+
bin/radiusparser radius.log parser that inserts data into the database.
2828

2929
sql/accounting_table.sql Script for creating the accounting table
3030
sql/log_table.sql Script for creating the log table
@@ -62,7 +62,7 @@ It should be pretty obvious that we have ripped extensively from NAV's
6262
MachineTracker subsystem, and at the time writing this, even the graphics in the
6363
tables are from MachineTracker.
6464

65-
There have yet to be confirmed reports on this stuff working (or even being
65+
There have yet to be confirmed reports on this stuff working (or even being
6666
tried) on any other setup than what it was developed on, which is:
6767

6868
* NAV v3.3.3
@@ -94,9 +94,9 @@ Hopefully it will be pretty self explanatory. You choose your search criteria
9494
and click the search button. The sessions that get matched are all sessions
9595
that "touch" your specified time interval in any way. At the bottom of the
9696
page, you will get a summary for your search, giving you the total amount of
97-
uploaded/downloaded data for all sessions matching your search criterias. This
98-
feature is currently made a bit useless from the duplicate sessions in the
99-
database (see `Known Issues`_).
97+
uploaded/downloaded data for all sessions matching your search criterias. This
98+
feature is currently made a bit useless from the duplicate sessions in the
99+
database (see `Known Issues`_).
100100

101101
In the search results, you will sometimes see sessions whose `Session Stop`
102102
field contains text in stead of the actual stop time. Here is an explanation
@@ -114,7 +114,7 @@ of what they mean:
114114

115115
For this feature to work correctly, the variable ``REAUTH_TIMEOUT`` in
116116
``radius_config.py`` must be set correctly
117-
117+
118118
There are links from `Username`, `Realm`, `Assigned IP` and `NAS IP`
119119
to new searches. I.e. clicking on a username will show all sessions for this
120120
user, using the already specified time interval. A click on a session id will
@@ -141,7 +141,7 @@ This chart will lie a little, since it sums up all sessions that ended within
141141
the specified number of days. The reason for doing this is that we only get any
142142
numbers on how much data the user has sent/received when the session ends. Thus
143143
there is really no way to know for sure, just from the radius accounting log,
144-
when during the session the data was transferred.
144+
when during the session the data was transferred.
145145

146146
Of course, we could always limit the search to sessions that only started
147147
inside our search interval, but then a lot of long sessions might slip under
@@ -165,18 +165,18 @@ Known Issues
165165
Accounting module: Duplicate entries for some sessions
166166
------------------------------------------------------
167167

168-
Sometimes, when a Start message is immediately followed by an Alive message for
169-
the same session, FreeRADIUS inserts the session into the database twice, the
170-
only difference between them seem to be a few hundreds of a second on the Start
168+
Sometimes, when a Start message is immediately followed by an Alive message for
169+
the same session, FreeRADIUS inserts the session into the database twice, the
170+
only difference between them seem to be a few hundreds of a second on the Start
171171
time. This seems to be caused by the following scenario:
172172

173173
1) FreeRADIUS receives a Start packet and inserts a new entry/session in the db
174-
2) FreeRADIUS receives an Alive packet for the same session *immediately* after
174+
2) FreeRADIUS receives an Alive packet for the same session *immediately* after
175175
the Start packet, and queries the database to see if the `unique-session-id`
176176
already exists.
177177
3) The query doesn't return anything, since postgresql hasn't had time to
178-
complete the `INSERT`-query for the Start packet, and
179-
``accounting_update_query_alt`` is thus run, inserting a new row.
178+
complete the `INSERT`-query for the Start packet, and
179+
``accounting_update_query_alt`` is thus run, inserting a new row.
180180

181181
How to get around this? I'm not quite sure. Maybe someone with more experience
182182
with (Postgre)SQL could look at some kind of table locking, if this wouldn't

doc/reference/smsd.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dispatcher handler layer.
1212
Usage
1313
=====
1414

15-
For more help on usage, run ``smsd.py --help`` and see the ``smsd.conf`` config
15+
For more help on usage, run ``smsd --help`` and see the ``smsd.conf`` config
1616
file.
1717

1818

doc/reference/snmptrapd.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Usage
2020
=====
2121

2222
snmptrapd can be started and stopped using the regular `nav start` and
23-
`nav stop` commands. The :program:`snmptrapd.py` program can also be run in
23+
`nav stop` commands. The :program:`snmptrapd` program can also be run in
2424
the foreground on the command line, logging all its activites to the
2525
standard output instead of the log file.
2626

@@ -30,7 +30,7 @@ the port is bound.
3030

3131
::
3232

33-
usage: snmptrapd.py [-h] [-d] [-c COMMUNITY] [address [address ...]]
33+
usage: snmptrapd [-h] [-d] [-c COMMUNITY] [address [address ...]]
3434

3535
NAV SNMP Trap daemon
3636

pyproject.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,42 @@ dependencies = [
2525
[project.urls]
2626
Homepage = "https://nav.uninett.no/"
2727

28+
[project.scripts]
29+
alertengine = "nav.bin.alertengine:main"
30+
autoenable = "nav.bin.autoenable:main"
31+
collect_active_ip = "nav.bin.collect_active_ip:main"
32+
emailreports = "nav.bin.emailreports:main"
33+
eventengine = "nav.bin.eventengine:main"
34+
ipdevpolld = "nav.bin.ipdevpolld:main"
35+
logengine = "nav.bin.logengine:main"
36+
macwatch = "nav.bin.macwatch:main"
37+
mailin = "nav.bin.mailin:main"
38+
maintengine = "nav.bin.maintengine:main"
39+
nav = "nav.bin.navmain:main"
40+
navcheckservice = "nav.bin.navcheckservice:main"
41+
navclean = "nav.bin.navclean:main"
42+
navdf = "nav.bin.navdf:main"
43+
navdump = "nav.bin.navdump:main"
44+
naventity = "nav.bin.naventity:main"
45+
navoidverify = "nav.bin.navoidverify:main"
46+
navpgdump = "nav.bin.navpgdump:main"
47+
navsnmp = "nav.bin.navsnmp:main"
48+
navstats = "nav.bin.navstats:main"
49+
navsyncdb = "nav.bin.navsyncdb:main"
50+
navsynctypes = "nav.bin.navsynctypes:main"
51+
navtopology = "nav.bin.navtopology:main"
52+
navuser = "nav.bin.navuser:main"
53+
netbiostracker = "nav.bin.netbiostracker:main"
54+
pping = "nav.bin.pping:main"
55+
radiusparser = "nav.bin.radiusparser:main"
56+
servicemon = "nav.bin.servicemon:main"
57+
smsd = "nav.bin.smsd:main"
58+
snmptrapd = "nav.bin.snmptrapd:main"
59+
sortedstats_cacher = "nav.bin.sortedstats_cacher:main"
60+
start_arnold = "nav.bin.start_arnold:main"
61+
t1000 = "nav.bin.t1000:main"
62+
thresholdmon = "nav.bin.thresholdmon:main"
63+
2864
[tool.setuptools]
2965
include-package-data = true
3066
zip-safe = false

python/nav/bin/__init__.py

Whitespace-only changes.
File renamed without changes.

bin/autoenable.py renamed to python/nav/bin/autoenable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Autoenable removes detention for computers that are done with detention.
2020
2121
Usage:
22-
sudo -u $NAV_USER ./autoenable.py
22+
sudo -u $NAV_USER autoenable
2323
2424
autoenable is meant to be run as a cronjob. It checks the configured
2525
arnold-database for any detained ports and opens them if they have a

0 commit comments

Comments
 (0)